File tree Expand file tree Collapse file tree 4 files changed +16
-8
lines changed
appengine-simple-jetty-main/src/main/java/com/example/appengine/demo/jettymain
http-server/src/main/java/com/example/appengine
sparkjava-helloworld/src/main/java/com/example/appengine/sparkdemo Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -32,11 +32,13 @@ public static void main(String[] args) throws Exception {
3232 System .setProperty ("org.eclipse.jetty.util.log.class" , "org.eclipse.jetty.util.log.StrErrLog" );
3333 System .setProperty ("org.eclipse.jetty.LEVEL" , "INFO" );
3434
35- // Create a basic Jetty server object that will listen on port 8080.
35+ // Create a basic Jetty server object that will listen on port defined by
36+ // the PORT environment variable when present, otherwise on 8080.
3637 // Note: If you set this to port 0, a randomly available port will be
3738 // assigned. You can find the assigned port in the logs or programmatically
3839 // obtain it.
39- Server server = new Server (8080 );
40+ int port = Integer .parseInt (System .getenv ().getOrDefault ("PORT" , "8080" ));
41+ Server server = new Server (port );
4042
4143 // The WebAppContext is the interface to provide configuration for a web
4244 // application. In this example, the context path is being set to "/" so
Original file line number Diff line number Diff line change 2323public class Main {
2424
2525 public static void main (String [] args ) throws IOException {
26- // Create an instance of HttpServer bound to port 8080.
27- HttpServer server = HttpServer .create (new InetSocketAddress (8080 ), 0 );
26+ // Create an instance of HttpServer bound to port defined by the
27+ // PORT environment variable when present, otherwise on 8080.
28+ int port = Integer .parseInt (System .getenv ().getOrDefault ("PORT" , "8080" ));
29+ HttpServer server = HttpServer .create (new InetSocketAddress (port ), 0 );
2830
2931 // Set root URI path.
3032 server .createContext ("/" , (var t ) -> {
Original file line number Diff line number Diff line change 2424public class Main {
2525
2626 public static void main (String [] args ) throws IOException {
27- // Create an instance of HttpServer with port 8080.
28- HttpServer server = HttpServer .create (new InetSocketAddress (8080 ), 0 );
27+ // Create an instance of HttpServer bound to port defined by the
28+ // PORT environment variable when present, otherwise on 8080.
29+ int port = Integer .parseInt (System .getenv ().getOrDefault ("PORT" , "8080" ));
30+ HttpServer server = HttpServer .create (new InetSocketAddress (port ), 0 );
2931
3032 // Set root URI path.
3133 server .createContext ("/" , (var t ) -> {
Original file line number Diff line number Diff line change 2121public class Main {
2222
2323 public static void main (String [] args ) {
24- // Starts the webapp on localhost:8080.
25- Spark .port (8080 );
24+ // Starts the webapp on localhost and the port defined by the PORT
25+ // environment variable when present, otherwise on 8080.
26+ int port = Integer .parseInt (System .getenv ().getOrDefault ("PORT" , "8080" ));
27+ Spark .port (port );
2628 Spark .get ("/" , (req , res ) -> "Hello World!" );
2729 }
2830}
You can’t perform that action at this time.
0 commit comments