| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:42:49 -06:00
										 |  |  | //var Greenlock = require('greenlock');
 | 
					
						
							|  |  |  | var Greenlock = require('../'); | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  | var db = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var config = { | 
					
						
							| 
									
										
										
										
											2018-05-19 17:42:49 -06:00
										 |  |  |   server: 'https://acme-v02.api.letsencrypt.org/directory' | 
					
						
							|  |  |  | , version: 'draft-11' | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 15:42:04 -06:00
										 |  |  | , configDir: require('os').homedir() + '/acme/etc'          // or /etc/acme or wherever
 | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | , privkeyPath: ':config/live/:hostname/privkey.pem'         //
 | 
					
						
							|  |  |  | , fullchainPath: ':config/live/:hostname/fullchain.pem'     // Note: both that :config and :hostname
 | 
					
						
							|  |  |  | , certPath: ':config/live/:hostname/cert.pem'               //       will be templated as expected
 | 
					
						
							|  |  |  | , chainPath: ':config/live/:hostname/chain.pem'             //
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | , rsaKeySize: 2048 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | , debug: true | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var handlers = { | 
					
						
							|  |  |  |   setChallenge: function (opts, hostname, key, val, cb) {   // called during the ACME server handshake, before validation
 | 
					
						
							|  |  |  |     db[key] = { | 
					
						
							|  |  |  |       hostname: hostname | 
					
						
							|  |  |  |     , key: key | 
					
						
							|  |  |  |     , val: val | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cb(null); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | , removeChallenge: function (opts, hostname, key, cb) {     // called after validation on both success and failure
 | 
					
						
							|  |  |  |     db[key] = null; | 
					
						
							|  |  |  |     cb(null); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | , getChallenge: function (opts, hostname, key, cb) {        // this is special because it is called by the webserver
 | 
					
						
							| 
									
										
										
										
											2018-05-15 15:42:04 -06:00
										 |  |  |     cb(null, db[key].val);                                  // (see greenlock-cli/bin & greenlock-express/standalone),
 | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  |                                                             // not by the library itself
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | , agreeToTerms: function (tosUrl, cb) {                     // gives you an async way to expose the legal agreement
 | 
					
						
							|  |  |  |     cb(null, tosUrl);                                       // (terms of use) to your users before accepting
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:42:49 -06:00
										 |  |  | var greenlock = Greenlock.create(config, handlers); | 
					
						
							| 
									
										
										
										
											2018-05-15 15:42:04 -06:00
										 |  |  | console.error("CHANGE THE EMAIL, DOMAINS, AND AGREE TOS IN THE EXAMPLE BEFORE RUNNING IT"); | 
					
						
							|  |  |  | process.exit(1); | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  |                                                             // checks :conf/renewal/:hostname.conf
 | 
					
						
							| 
									
										
										
										
											2018-05-19 17:42:49 -06:00
										 |  |  | greenlock.register({                                        // and either renews or registers
 | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  |   domains: ['example.com']                                  // CHANGE TO YOUR DOMAIN
 | 
					
						
							|  |  |  | , email: 'user@email.com'                                   // CHANGE TO YOUR EMAIL
 | 
					
						
							|  |  |  | , agreeTos: false                                           // set to true to automatically accept an agreement
 | 
					
						
							|  |  |  |                                                             // which you have pre-approved (not recommended)
 | 
					
						
							|  |  |  | , rsaKeySize: 2048 | 
					
						
							|  |  |  | }, function (err) { | 
					
						
							|  |  |  |   if (err) { | 
					
						
							|  |  |  |     // Note: you must have a webserver running
 | 
					
						
							|  |  |  |     // and expose handlers.getChallenge to it
 | 
					
						
							|  |  |  |     // in order to pass validation
 | 
					
						
							| 
									
										
										
										
											2018-05-15 15:42:04 -06:00
										 |  |  |     // See greenlock-cli and or greenlock-express
 | 
					
						
							|  |  |  |     console.error('[Error]: greenlock/examples/standalone'); | 
					
						
							| 
									
										
										
										
											2016-08-04 18:49:35 -04:00
										 |  |  |     console.error(err.stack); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     console.log('success'); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); |