GeezerVison is showing github.com — Make sure samples listen to PORT env var (#1598) · dmichel1/java-docs-samples@501af84
File tree
Expand file treeCollapse file tree
Open diff view settings
appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain springboot-helloworld/src/main/resources vertx-helloworld/src/main/java/com/example/appengine/vertxhello
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: appengine-java11/appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain/Main.java -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,9 +34,6 @@ public static void main(String[] args) throws Exception { |
34 | 34 |
|
35 | 35 | // Create a basic Jetty server object that will listen on port defined by |
36 | 36 | // 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. |
40 | 37 | int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080")); |
41 | 38 | Server server = new Server(port); |
42 | 39 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: appengine-java11/quarkus-helloworld/pom.xml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
82 | 82 | <!-- Copy dependencies of exploded fatjar to appengine-staging directory --> |
83 | 83 | <configuration> |
84 | 84 | <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> |
86 | 86 | </configuration> |
87 | 87 | </plugin> |
88 | 88 | <!-- Set Surefire version to work with Junit5 --> |
|
Collapse file
Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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} |
Collapse file
Copy file name to clipboardExpand all lines: appengine-java11/springboot-helloworld/src/main/resources/application.properties +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | + |
| 15 | +# Set the port to the PORT environment variable |
| 16 | +server.port=${PORT:8080} |
Collapse file
Copy file name to clipboardExpand all lines: appengine-java11/vertx-helloworld/src/main/java/com/example/appengine/vertxhello/Application.java +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,10 +37,13 @@ public void start(Future<Void> startFuture) { |
37 | 37 | Router router = Router.router(vertx); |
38 | 38 | router.route().handler(this::handleDefault); |
39 | 39 |
|
| 40 | + // Get the PORT environment variable for the server object to listen on |
| 41 | + int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080")); |
| 42 | + |
40 | 43 | vertx |
41 | 44 | .createHttpServer() |
42 | 45 | .requestHandler(router) |
43 | | - .listen(8080, ar -> startFuture.handle(ar.mapEmpty())); |
| 46 | + .listen(port, ar -> startFuture.handle(ar.mapEmpty())); |
44 | 47 | } |
45 | 48 |
|
46 | 49 | private void handleDefault(RoutingContext routingContext) { |
|