updates
This commit is contained in:
parent
88406b9c0b
commit
1e4affc079
|
@ -1,3 +1,7 @@
|
|||
letsencrypt.work
|
||||
letsencrypt.logs
|
||||
letsencrypt.config
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
|
|
@ -1,36 +1,52 @@
|
|||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var leBinPath = require('homedir')() + '/.local/share/letsencrypt/bin/letsencrypt';
|
||||
var lep = require('letsencrypt-python').create(leBinPath);
|
||||
var LEP = require('letsencrypt-python');
|
||||
var lep = LEP.create(leBinPath, { debug: true });
|
||||
var conf = {
|
||||
domains: process.argv[2]
|
||||
, email: process.argv[3]
|
||||
, agree: process.argv[4]
|
||||
};
|
||||
var port = 80;
|
||||
var tlsPort = 5001;
|
||||
|
||||
if (!conf.domains || !conf.email || !conf.agree) {
|
||||
console.error("Usage: letsencrypt <domain1,domain2> <email> agree");
|
||||
console.error("Example: letsencrypt example.com,www.example.com user@example.com agree");
|
||||
return;
|
||||
}
|
||||
|
||||
// backend-specific defaults
|
||||
// Note: For legal reasons you should NOT set email or agreeTos as a default
|
||||
var bkDefaults = {
|
||||
webroot: true
|
||||
, webrootPath: __dirname + '/acme-challenge'
|
||||
, webrootPath: path.join(__dirname, '..', 'tests', 'acme-challenge')
|
||||
, fullchainTpl: '/live/:hostname/fullchain.pem'
|
||||
, privkeyTpl: '/live/:hostname/fullchain.pem'
|
||||
, configDir: '/etc/letsencrypt'
|
||||
, logsDir: '/var/log/letsencrypt'
|
||||
, workDir: '/var/lib/letsencrypt'
|
||||
, configDir: path.join(__dirname, '..', 'tests', 'letsencrypt.config')
|
||||
, logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs')
|
||||
, workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work')
|
||||
, server: LEP.stagingServer
|
||||
, text: true
|
||||
};
|
||||
var le = require('../').create(lep, bkDefaults);
|
||||
var le = require('../').create(lep, bkDefaults, {
|
||||
});
|
||||
|
||||
var localCerts = require('localhost.daplie.com-certificates');
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
app.use(le.middleware());
|
||||
app.use('/', function (req, res, next) {
|
||||
console.log('[DEBUG]', req.method, req.protocol, req.hostname, req.url);
|
||||
next();
|
||||
});
|
||||
app.use('/', le.middleware());
|
||||
|
||||
var server = require('http').createServer();
|
||||
server.on('request', app);
|
||||
server.listen(80, function () {
|
||||
server.listen(port, function () {
|
||||
console.log('Listening http', server.address());
|
||||
});
|
||||
|
||||
|
@ -40,7 +56,7 @@ var tlsServer = require('https').createServer({
|
|||
, SNICallback: le.sniCallback
|
||||
});
|
||||
tlsServer.on('request', app);
|
||||
tlsServer.listen(443, function () {
|
||||
tlsServer.listen(tlsPort, function () {
|
||||
console.log('Listening http', tlsServer.address());
|
||||
});
|
||||
|
||||
|
|
21
index.js
21
index.js
|
@ -1,7 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
var PromiseA = require('bluebird');
|
||||
|
||||
module.exports.create = function (letsencrypt, defaults, options) {
|
||||
var PromiseA = require('bluebird');
|
||||
letsencrypt = PromiseA.promisifyAll(letsencrypt);
|
||||
var tls = require('tls');
|
||||
var fs = PromiseA.promisifyAll(require('fs'));
|
||||
var utils = require('./utils');
|
||||
|
@ -28,18 +30,24 @@ module.exports.create = function (letsencrypt, defaults, options) {
|
|||
var now;
|
||||
var le;
|
||||
|
||||
options.cacheContextsFor = options.cacheContextsFor || (1 * 60 * 60 * 1000);
|
||||
// TODO check certs on initial load
|
||||
// TODO expect that certs expire every 90 days
|
||||
// TODO check certs with setInterval?
|
||||
//options.cacheContextsFor = options.cacheContextsFor || (1 * 60 * 60 * 1000);
|
||||
|
||||
defaults.webroot = true;
|
||||
|
||||
function merge(args) {
|
||||
var copy = {};
|
||||
|
||||
Object.keys(defaults).forEach(function (key) {
|
||||
copy[key] = defaults[key];
|
||||
});
|
||||
Object.keys(args).forEach(function (key) {
|
||||
copy[key] = args[key];
|
||||
});
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
function sniCallback(hostname, cb) {
|
||||
|
@ -65,21 +73,28 @@ module.exports.create = function (letsencrypt, defaults, options) {
|
|||
|
||||
le = {
|
||||
validate: function () {
|
||||
// TODO check dns, etc
|
||||
return PromiseA.resolve();
|
||||
}
|
||||
, middleware: function () {
|
||||
console.log('[DEBUG] webrootPath', defaults.webrootPath);
|
||||
var serveStatic = require('serve-static')(defaults.webrootPath);
|
||||
var prefix = '/.well-known/acme-challenge/';
|
||||
|
||||
return function (req, res, next) {
|
||||
if (0 === req.url.indexOf(prefix)) {
|
||||
if (0 !== req.url.indexOf(prefix)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[DEBUG] req.url 0', req.url);
|
||||
var pathname = req.url;
|
||||
req.url = req.url.substr(prefix.length - 1);
|
||||
console.log('[DEBUG] req.url 1', req.url);
|
||||
serveStatic(req, res, function (err) {
|
||||
console.log('[DEBUG] req.url 2', req.url);
|
||||
req.url = pathname;
|
||||
console.log('[DEBUG] req.url 3', req.url);
|
||||
next(err);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
"localhost.daplie.com-certificates": "^1.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"letsencrypt-python": "^1.0.3"
|
||||
"bluebird": "^3.0.6",
|
||||
"letsencrypt-python": "^1.0.3",
|
||||
"serve-static": "^1.10.0"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue