Skip to content

Commit 501af84

Browse files
authored
Make sure samples listen to PORT env var (#1598)
1 parent decd51a commit 501af84

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

appengine-java11/appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain/Main.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public static void main(String[] args) throws Exception {
3434

3535
// Create a basic Jetty server object that will listen on port defined by
3636
// the PORT environment variable when present, otherwise on 8080.
37-
// Note: If you set this to port 0, a randomly available port will be
38-
// assigned. You can find the assigned port in the logs or programmatically
39-
// obtain it.
4037
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
4138
Server server = new Server(port);
4239

appengine-java11/quarkus-helloworld/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<!-- Copy dependencies of exploded fatjar to appengine-staging directory -->
8383
<configuration>
8484
<libDir>${project.build.directory}/appengine-staging/lib</libDir>
85-
<finalName>${project.build.directory}/appengine-staging/${build.finalName}</finalName>
85+
<finalName>${project.build.directory}/appengine-staging/${project.build.finalName}</finalName>
8686
</configuration>
8787
</plugin>
8888
<!-- Set Surefire version to work with Junit5 -->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Set the port to the PORT environment variable
16+
quarkus.http.port=${PORT:8080}

appengine-java11/springboot-helloworld/src/main/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
15+
# Set the port to the PORT environment variable
16+
server.port=${PORT:8080}

appengine-java11/vertx-helloworld/src/main/java/com/example/appengine/vertxhello/Application.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ public void start(Future<Void> startFuture) {
3737
Router router = Router.router(vertx);
3838
router.route().handler(this::handleDefault);
3939

40+
// Get the PORT environment variable for the server object to listen on
41+
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
42+
4043
vertx
4144
.createHttpServer()
4245
.requestHandler(router)
43-
.listen(8080, ar -> startFuture.handle(ar.mapEmpty()));
46+
.listen(port, ar -> startFuture.handle(ar.mapEmpty()));
4447
}
4548

4649
private void handleDefault(RoutingContext routingContext) {

0 commit comments

Comments
 (0)