fix #2 loopback port and timeout
This commit is contained in:
		
							parent
							
								
									f64583d619
								
							
						
					
					
						commit
						458cf2faff
					
				| @ -10,7 +10,7 @@ | |||||||
| 
 | 
 | ||||||
| # le-challenge-webroot | # le-challenge-webroot | ||||||
| 
 | 
 | ||||||
| A fs-based strategy for node-letsencrypt for setting, retrieving, | An fs-based strategy for node-letsencrypt for setting, retrieving, | ||||||
| and clearing ACME challenges issued by the ACME server | and clearing ACME challenges issued by the ACME server | ||||||
| 
 | 
 | ||||||
| This places the acme challenge in an appropriate directory in the specified `webrootPath` | This places the acme challenge in an appropriate directory in the specified `webrootPath` | ||||||
| @ -31,7 +31,9 @@ Usage | |||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| var leChallenge = require('le-challenge-fs').create({ | var leChallenge = require('le-challenge-fs').create({ | ||||||
|   webrootPath: '~/letsencrypt/srv/www/:hostname/.well-known/acme-challenge' |   webrootPath: '~/letsencrypt/srv/www/:hostname/.well-known/acme-challenge'   // defaults to os.tmpdir() | ||||||
|  | , loopbackPort: 5001                                                          // defaults to 80 | ||||||
|  | , loopbackTimeout: 3000                                                       // defaults to 3000ms | ||||||
| , debug: false | , debug: false | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										8
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								index.js
									
									
									
									
									
								
							| @ -6,6 +6,7 @@ var path = require('path'); | |||||||
| var myDefaults = { | var myDefaults = { | ||||||
|   //webrootPath: [ '~', 'letsencrypt', 'var', 'lib' ].join(path.sep)
 |   //webrootPath: [ '~', 'letsencrypt', 'var', 'lib' ].join(path.sep)
 | ||||||
|   webrootPath: path.join(require('os').tmpdir(), 'acme-challenge') |   webrootPath: path.join(require('os').tmpdir(), 'acme-challenge') | ||||||
|  | , loopbackTimeout: 5 * 1000 | ||||||
| , debug: false | , debug: false | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -69,7 +70,7 @@ Challenge.remove = function (defaults, domain, key, done) { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| Challenge.loopback = function (defaults, domain, key, done) { | Challenge.loopback = function (defaults, domain, key, done) { | ||||||
|   var hostname = domain + (defaults.test ? ':' + defaults.test : ''); |   var hostname = domain + (defaults.loopbackPort ? ':' + defaults.loopbackPort : ''); | ||||||
|   var urlstr = 'http://' + hostname + '/.well-known/acme-challenge/' + key; |   var urlstr = 'http://' + hostname + '/.well-known/acme-challenge/' + key; | ||||||
| 
 | 
 | ||||||
|   require('http').get(urlstr, function (res) { |   require('http').get(urlstr, function (res) { | ||||||
| @ -85,6 +86,8 @@ Challenge.loopback = function (defaults, domain, key, done) { | |||||||
|       var str = Buffer.concat(chunks).toString('utf8').trim(); |       var str = Buffer.concat(chunks).toString('utf8').trim(); | ||||||
|       done(null, str); |       done(null, str); | ||||||
|     }); |     }); | ||||||
|  |   }).setTimeout(defaults.loopbackTimeout, function () { | ||||||
|  |     done(new Error("loopback timeout, could not reach server")); | ||||||
|   }).on('error', function (err) { |   }).on('error', function (err) { | ||||||
|     done(err); |     done(err); | ||||||
|   }); |   }); | ||||||
| @ -97,8 +100,7 @@ Challenge.test = function (args, domain, challenge, keyAuthorization, done) { | |||||||
|   me.set(args, domain, challenge, key, function (err) { |   me.set(args, domain, challenge, key, function (err) { | ||||||
|     if (err) { done(err); return; } |     if (err) { done(err); return; } | ||||||
| 
 | 
 | ||||||
|     // test is actually the port to be used
 |     myDefaults.loopbackPort = args.loopbackPort; | ||||||
|     myDefaults.test = args.test; |  | ||||||
|     myDefaults.webrootPath = args.webrootPath; |     myDefaults.webrootPath = args.webrootPath; | ||||||
|     me.loopback(args, domain, challenge, function (err, _key) { |     me.loopback(args, domain, challenge, function (err, _key) { | ||||||
|       if (err) { done(err); return; } |       if (err) { done(err); return; } | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								test.js
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								test.js
									
									
									
									
									
								
							| @ -59,7 +59,8 @@ function loopbackTest() { | |||||||
|     var port = server.address().port; |     var port = server.address().port; | ||||||
| 
 | 
 | ||||||
|     opts.webrootPath = webrootPath; |     opts.webrootPath = webrootPath; | ||||||
|     opts.test = port; |     opts.loopbackPort = port; | ||||||
|  |     opts.loopbackTimeout = 500; | ||||||
|     challenge.test(opts, 'localhost', 'foo', 'bar', function (err) { |     challenge.test(opts, 'localhost', 'foo', 'bar', function (err) { | ||||||
|       server.close(); |       server.close(); | ||||||
|       if (err) { console.error(err.stack); return; } |       if (err) { console.error(err.stack); return; } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user