fix #2 loopback port and timeout

This commit is contained in:
AJ ONeal 2016-10-12 16:51:41 -06:00
부모 f64583d619
커밋 458cf2faff
3개의 변경된 파일11개의 추가작업 그리고 6개의 파일을 삭제

파일 보기

@ -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
}); });

파일 보기

@ -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; }

파일 보기

@ -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; }