WIP cleanup
This commit is contained in:
		
							parent
							
								
									aac54d63f2
								
							
						
					
					
						commit
						0285f9b40f
					
				
							
								
								
									
										88
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								index.js
									
									
									
									
									
								
							| @ -10,18 +10,9 @@ try { | |||||||
| // opts.approveDomains(options, certs, cb)
 | // opts.approveDomains(options, certs, cb)
 | ||||||
| module.exports.create = function (opts) { | module.exports.create = function (opts) { | ||||||
|   // accept all defaults for greenlock.challenges, greenlock.store, greenlock.middleware
 |   // accept all defaults for greenlock.challenges, greenlock.store, greenlock.middleware
 | ||||||
|   opts._communityPackage = opts._communityPackage || 'greenlock-express.js'; |   if (!opts._communityPackage) { | ||||||
|   var greenlock = require('greenlock').create(opts); |     opts._communityPackage = 'greenlock-express.js'; | ||||||
| 
 |   } | ||||||
|   opts.app = opts.app || function (req, res) { |  | ||||||
|     res.end("Hello, World!\nWith Love,\nGreenlock for Express.js"); |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
|   opts.listen = function (plainPort, port) { |  | ||||||
|     var promises = []; |  | ||||||
|     var plainPorts = plainPort; |  | ||||||
|     var ports = port; |  | ||||||
|     var servers = []; |  | ||||||
| 
 | 
 | ||||||
|   function explainError(e) { |   function explainError(e) { | ||||||
|     console.error('Error:' + e.message); |     console.error('Error:' + e.message); | ||||||
| @ -38,22 +29,16 @@ module.exports.create = function (opts) { | |||||||
|     console.error(e.code + ": '" + e.address + ":" + e.port + "'"); |     console.error(e.code + ": '" + e.address + ":" + e.port + "'"); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|     if (!plainPorts) { |   function _listenHttp(plainPort) { | ||||||
|       plainPorts = 80; |     if (!plainPort) { plainPort = 80; } | ||||||
|     } |     var p = plainPort; | ||||||
|     if (!ports) { |     var validHttpPort = (parseInt(p, 10) >= 0); | ||||||
|       ports = 443; |     if (!validHttpPort) { console.warn("'" + p + "' doesn't seem to be a valid port number for http"); } | ||||||
|     } |     var plainServer = require('http').createServer( | ||||||
| 
 |       greenlock.middleware.sanitizeHost(greenlock.middleware(require('redirect-https')())) | ||||||
|     if (!Array.isArray(plainPorts)) { |     ); | ||||||
|       plainPorts = [ plainPorts ]; |     var promise = new PromiseA(function (resolve) { | ||||||
|       ports = [ ports ]; |       plainServer.listen(p, function () { | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     plainPorts.forEach(function (p) { |  | ||||||
|       if (!(parseInt(p, 10) >= 0)) { console.warn("'" + p + "' doesn't seem to be a valid port number for http"); } |  | ||||||
|       promises.push(new PromiseA(function (resolve) { |  | ||||||
|         require('http').createServer(greenlock.middleware(require('redirect-https')())).listen(p, function () { |  | ||||||
|         console.log("Success! Bound to port '" + p + "' to handle ACME challenges and redirect to https"); |         console.log("Success! Bound to port '" + p + "' to handle ACME challenges and redirect to https"); | ||||||
|         resolve(); |         resolve(); | ||||||
|       }).on('error', function (e) { |       }).on('error', function (e) { | ||||||
| @ -61,12 +46,17 @@ module.exports.create = function (opts) { | |||||||
|         explainError(e); |         explainError(e); | ||||||
|         process.exit(0); |         process.exit(0); | ||||||
|       }); |       }); | ||||||
|       })); |  | ||||||
|     }); |     }); | ||||||
|  |     promise.server = plainServer; | ||||||
|  |     return promise; | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|     ports.forEach(function (p) { |   function _listenHttps(port) { | ||||||
|       if (!(parseInt(p, 10) >= 0)) { console.warn("'" + p + "' doesn't seem to be a valid port number for https"); } |     if (!port) { port = 443; } | ||||||
|       promises.push(new PromiseA(function (resolve) { | 
 | ||||||
|  |     var p = port; | ||||||
|  |     var validHttpsPort = (parseInt(p, 10) >= 0); | ||||||
|  |     if (!validHttpsPort) { console.warn("'" + p + "' doesn't seem to be a valid port number for https"); } | ||||||
|     var https; |     var https; | ||||||
|     try { |     try { | ||||||
|       https = require('spdy'); |       https = require('spdy'); | ||||||
| @ -74,23 +64,41 @@ module.exports.create = function (opts) { | |||||||
|     } catch(e) { |     } catch(e) { | ||||||
|       https = require('https'); |       https = require('https'); | ||||||
|     } |     } | ||||||
|         var server = https.createServer(greenlock.tlsOptions, greenlock.middleware(greenlock.app)).listen(p, function () { |     var server = https.createServer( | ||||||
|  |       greenlock.tlsOptions | ||||||
|  |     , greenlock.middleware.sanitizeHost(function (req, res) { | ||||||
|  |         try { | ||||||
|  |           greenlock.app(req, res); | ||||||
|  |         } catch(e) { | ||||||
|  |           console.error("[error] [greenlock.app] Your HTTP handler had an uncaught error:"); | ||||||
|  |           console.error(e); | ||||||
|  |         } | ||||||
|  |       }) | ||||||
|  |     ); | ||||||
|  |     var promise = new PromiseA(function (resolve) { | ||||||
|  |       server.listen(p, function () { | ||||||
|         console.log("Success! Serving https on port '" + p + "'"); |         console.log("Success! Serving https on port '" + p + "'"); | ||||||
|           resolve(); |         resolve(server); | ||||||
|       }).on('error', function (e) { |       }).on('error', function (e) { | ||||||
|         console.log("Did not successfully create https server and bind to port '" + p + "':"); |         console.log("Did not successfully create https server and bind to port '" + p + "':"); | ||||||
|         explainError(e); |         explainError(e); | ||||||
|         process.exit(0); |         process.exit(0); | ||||||
|       }); |       }); | ||||||
|         servers.push(server); |  | ||||||
|       })); |  | ||||||
|     }); |     }); | ||||||
| 
 |     promise.server = server; | ||||||
|     if (!Array.isArray(port)) { |     return promise; | ||||||
|       servers = servers[0]; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|     return servers; |   var greenlock = require('greenlock').create(opts); | ||||||
|  | 
 | ||||||
|  |   opts.app = opts.app || function (req, res) { | ||||||
|  |     res.end("Hello, World!\nWith Love,\nGreenlock for Express.js"); | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  |   opts.listen = function (plainPort, port) { | ||||||
|  |     var promises = []; | ||||||
|  |     promises.push(_listenHttp(plainPort)); | ||||||
|  |     promises.push(_listenHttps(port)); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "greenlock-express", |   "name": "greenlock-express", | ||||||
|   "version": "2.3.2", |   "version": "2.3.3", | ||||||
|   "description": "Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.", |   "description": "Free SSL and managed or automatic HTTPS for node.js with Express, Koa, Connect, Hapi, and all other middleware systems.", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "homepage": "https://git.coolaj86.com/coolaj86/greenlock-express.js", |   "homepage": "https://git.coolaj86.com/coolaj86/greenlock-express.js", | ||||||
| @ -8,7 +8,7 @@ | |||||||
|     "example": "examples" |     "example": "examples" | ||||||
|   }, |   }, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "greenlock": "^2.3.7", |     "greenlock": "^2.3.10", | ||||||
|     "le-challenge-fs": "^2.0.8", |     "le-challenge-fs": "^2.0.8", | ||||||
|     "le-sni-auto": "^2.1.4", |     "le-sni-auto": "^2.1.4", | ||||||
|     "le-store-certbot": "^2.1.0", |     "le-store-certbot": "^2.1.0", | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user