mirror of
				https://github.com/therootcompany/greenlock-express.js.git
				synced 2024-11-16 17:28:59 +00:00 
			
		
		
		
	time to go nani nani... tired
This commit is contained in:
		
							parent
							
								
									f9e75faba7
								
							
						
					
					
						commit
						0071264d39
					
				
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							| @ -1,18 +1,13 @@ | |||||||
| letsencrypt-cluster | letsencrypt-express | ||||||
| =================== | =================== | ||||||
| 
 | 
 | ||||||
| Use automatic letsencrypt with node on multiple cores or even multiple machines. | Use automatic letsencrypt with express and other node http frameworks. | ||||||
| 
 |  | ||||||
| * Take advantage of multi-core computing |  | ||||||
| * Process certificates in master |  | ||||||
| * Serve https from multiple workers |  | ||||||
| * Can work with any clustering strategy [#1](https://github.com/Daplie/letsencrypt-cluster/issues/1) |  | ||||||
| 
 | 
 | ||||||
| Install | Install | ||||||
| ======= | ======= | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| npm install --save letsencrypt-cluster@2.x | npm install --save letsencrypt-express@2.x | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| Usage | Usage | ||||||
|  | |||||||
							
								
								
									
										73
									
								
								master.js
									
									
									
									
									
								
							
							
						
						
									
										73
									
								
								master.js
									
									
									
									
									
								
							| @ -87,5 +87,78 @@ module.exports.create = function (opts) { | |||||||
|     }); |     }); | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |   return opts; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | module.exports.create = function (opts) { | ||||||
|  | 
 | ||||||
|  |   // if another worker updates the certs,
 | ||||||
|  |   // receive a copy from master here as well
 | ||||||
|  |   // and update the sni cache manually
 | ||||||
|  |   process.on('message', function (msg) { | ||||||
|  |     if ('LE_RESPONSE' === msg.type && msg.certs) { | ||||||
|  |       opts.sni.cacheCerts(msg.certs); | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   opts.sni = require('le-sni-auto').create({ | ||||||
|  |     renewWithin: opts.renewWithin || (10 * 24 * 60 * 60 * 1000) | ||||||
|  |   , renewBy: opts.renewBy || (5 * 24 * 60 * 60 * 1000) | ||||||
|  |   , getCertificates: function (domain, certs, cb) { | ||||||
|  |       var workerOptions = { domains: [ domain ] }; | ||||||
|  |       opts.approveDomains(workerOptions, certs, function (_err, results) { | ||||||
|  |         if (_err) { | ||||||
|  |           cb(_err); | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         var err = new Error("___MESSAGE___"); | ||||||
|  |         process.send({ type: 'LE_REQUEST', domain: domain, options: results.options, certs: results.certs }); | ||||||
|  | 
 | ||||||
|  |         process.on('message', function (msg) { | ||||||
|  |           log(opts.debug, 'Message from master'); | ||||||
|  |           log(opts.debug, msg); | ||||||
|  | 
 | ||||||
|  |           if (msg.domain !== domain) { | ||||||
|  |             return; | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           if (msg.error) { | ||||||
|  |             err.message = msg.error.message || "unknown error sent from cluster master to worker"; | ||||||
|  |             err.stack.replace("___MESSAGE___", err.message); | ||||||
|  |             err = { | ||||||
|  |               message: err.message | ||||||
|  |             , stack: err.stack | ||||||
|  |             , data: { options: workerOptions, certs: certs } | ||||||
|  |             }; | ||||||
|  |           } else { | ||||||
|  |             err = null; | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           cb(err, msg.certs); | ||||||
|  |         }); | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   opts.httpsOptions = require('localhost.daplie.com-certificates').merge({ SNICallback: opts.sni.sniCallback }); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   opts.challenge = { | ||||||
|  |     get: opts.getChallenge | ||||||
|  |       || (opts.challenge && opts.challenge.get) | ||||||
|  |       || require('le-challenge-fs').create({ webrootPath: opts.webrootPath }).get | ||||||
|  |   }; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |   // opts.challenge.get, opts.acmeChallengePrefix
 | ||||||
|  |   opts.middleware = require('letsencrypt/lib/middleware').create(opts); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|   return opts; |   return opts; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "letsencrypt-cluster", |   "name": "letsencrypt-express", | ||||||
|   "version": "2.0.0", |   "version": "2.0.0", | ||||||
|   "description": "Use automatic letsencrypt (free ssl certs) on multiple cores or even multiple machines", |   "description": "Use automatic letsencrypt (free ssl certs) with node http frameworks such as express", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "directories": { |   "directories": { | ||||||
|     "example": "examples" |     "example": "examples" | ||||||
|  | |||||||
							
								
								
									
										87
									
								
								worker.js
									
									
									
									
									
								
							
							
						
						
									
										87
									
								
								worker.js
									
									
									
									
									
								
							| @ -1,87 +0,0 @@ | |||||||
| 'use strict'; |  | ||||||
| 
 |  | ||||||
| function log(debug) { |  | ||||||
| 	if (!debug) { |  | ||||||
| 		return; |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	var args = Array.prototype.slice.call(arguments); |  | ||||||
| 	args.shift(); |  | ||||||
| 	args.unshift("[le/lib/core.js]"); |  | ||||||
| 	console.log.apply(console, args); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| module.exports.create = function (opts) { |  | ||||||
| 
 |  | ||||||
|   // if another worker updates the certs,
 |  | ||||||
|   // receive a copy from master here as well
 |  | ||||||
|   // and update the sni cache manually
 |  | ||||||
|   process.on('message', function (msg) { |  | ||||||
|     if ('LE_RESPONSE' === msg.type && msg.certs) { |  | ||||||
|       opts.sni.cacheCerts(msg.certs); |  | ||||||
|     } |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
|   opts.sni = require('le-sni-auto').create({ |  | ||||||
|     renewWithin: opts.renewWithin || (10 * 24 * 60 * 60 * 1000) |  | ||||||
|   , renewBy: opts.renewBy || (5 * 24 * 60 * 60 * 1000) |  | ||||||
|   , getCertificates: function (domain, certs, cb) { |  | ||||||
|       var workerOptions = { domains: [ domain ] }; |  | ||||||
|       opts.approveDomains(workerOptions, certs, function (_err, results) { |  | ||||||
|         if (_err) { |  | ||||||
|           cb(_err); |  | ||||||
|           return; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         var err = new Error("___MESSAGE___"); |  | ||||||
|         process.send({ type: 'LE_REQUEST', domain: domain, options: results.options, certs: results.certs }); |  | ||||||
| 
 |  | ||||||
|         process.on('message', function (msg) { |  | ||||||
|           log(opts.debug, 'Message from master'); |  | ||||||
|           log(opts.debug, msg); |  | ||||||
| 
 |  | ||||||
|           if (msg.domain !== domain) { |  | ||||||
|             return; |  | ||||||
|           } |  | ||||||
| 
 |  | ||||||
|           if (msg.error) { |  | ||||||
|             err.message = msg.error.message || "unknown error sent from cluster master to worker"; |  | ||||||
|             err.stack.replace("___MESSAGE___", err.message); |  | ||||||
|             err = { |  | ||||||
|               message: err.message |  | ||||||
|             , stack: err.stack |  | ||||||
|             , data: { options: workerOptions, certs: certs } |  | ||||||
|             }; |  | ||||||
|           } else { |  | ||||||
|             err = null; |  | ||||||
|           } |  | ||||||
| 
 |  | ||||||
|           cb(err, msg.certs); |  | ||||||
|         }); |  | ||||||
|       }); |  | ||||||
|     } |  | ||||||
|   }); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   opts.httpsOptions = require('localhost.daplie.com-certificates').merge({ SNICallback: opts.sni.sniCallback }); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   opts.challenge = { |  | ||||||
|     get: opts.getChallenge |  | ||||||
|       || (opts.challenge && opts.challenge.get) |  | ||||||
|       || require('le-challenge-fs').create({ webrootPath: opts.webrootPath }).get |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   // opts.challenge.get, opts.acmeChallengePrefix
 |  | ||||||
|   opts.middleware = require('letsencrypt/lib/middleware').create(opts); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   return opts; |  | ||||||
| }; |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user