| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The WRONG way:
 | 
					
						
							|  |  |  | //var http2 = require('http2');
 | 
					
						
							|  |  |  | //var http2Server = https.createSecureServer(tlsOptions, app);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Why is that wrong?
 | 
					
						
							|  |  |  | // Greenlock needs to change some low-level http and https options.
 | 
					
						
							|  |  |  | // Use glx.httpsServer(tlsOptions, app) instead.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-10 17:51:25 -07:00
										 |  |  | //require("greenlock-express")
 | 
					
						
							|  |  |  | require("../../") | 
					
						
							|  |  |  |     .init({ | 
					
						
							|  |  |  |         packageRoot: __dirname, | 
					
						
							|  |  |  |         configDir: "./greenlock.d", | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         maintainerEmail: "jon@example.com", | 
					
						
							|  |  |  |         cluster: false | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     .ready(httpsWorker); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | function httpsWorker(glx) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     // HTTP2 would have been the default httpsServer for node v12+
 | 
					
						
							|  |  |  |     // However... https://github.com/expressjs/express/issues/3388
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Get the raw http2 server:
 | 
					
						
							| 
									
										
										
										
											2020-08-03 06:37:24 +00:00
										 |  |  |     var tlsOptions = null; | 
					
						
							|  |  |  |     var http2Server = glx.http2Server(tlsOptions, function(req, res) { | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |         res.end("Hello, Encrypted World!"); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     http2Server.listen(443, "0.0.0.0", function() { | 
					
						
							|  |  |  |         console.info("Listening on ", http2Server.address()); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Note:
 | 
					
						
							|  |  |  |     // You must ALSO listen on port 80 for ACME HTTP-01 Challenges
 | 
					
						
							|  |  |  |     // (the ACME and http->https middleware are loaded by glx.httpServer)
 | 
					
						
							|  |  |  |     var httpServer = glx.httpServer(); | 
					
						
							| 
									
										
										
										
											2020-01-10 17:51:25 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 15:14:07 -06:00
										 |  |  |     httpServer.listen(80, "0.0.0.0", function() { | 
					
						
							|  |  |  |         console.info("Listening on ", httpServer.address()); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-11-01 04:12:40 -06:00
										 |  |  | } |