fix getChallenge (missing webrootPath) and update examples
This commit is contained in:
parent
d1375aceb0
commit
6e0ba823d2
|
@ -171,7 +171,6 @@ Let's say you want to redirect all http to https.
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var https = require('https');
|
var https = require('https');
|
||||||
var LEX = require('letsencrypt-express');
|
var LEX = require('letsencrypt-express');
|
||||||
var LE = require('letsencrypt');
|
|
||||||
|
|
||||||
var lex = LEX.create({
|
var lex = LEX.create({
|
||||||
configDir: __dirname + '/letsencrypt.config'
|
configDir: __dirname + '/letsencrypt.config'
|
||||||
|
@ -184,6 +183,7 @@ var lex = LEX.create({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) {
|
http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) {
|
||||||
res.setHeader('Location', 'https://' + req.headers.host + req.url);
|
res.setHeader('Location', 'https://' + req.headers.host + req.url);
|
||||||
res.end('<!-- Hello Mr Developer! Please use HTTPS instead -->');
|
res.end('<!-- Hello Mr Developer! Please use HTTPS instead -->');
|
||||||
|
@ -199,6 +199,12 @@ app.use('/', function (req, res) {
|
||||||
https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app));
|
https.createServer(lex.httpsOptions, LEX.createAcmeResponder(lex, app));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In short these are the only functions you need to be aware of:
|
||||||
|
|
||||||
|
* `LEX.create(opts)`
|
||||||
|
* `{ configDir: pathname, approveRegistration: func }`
|
||||||
|
* `LEX.createAcmeResponder(lex, onRequest)`
|
||||||
|
|
||||||
### WebSockets with Let's Encrypt
|
### WebSockets with Let's Encrypt
|
||||||
|
|
||||||
Note: you don't need to create websockets for the plain ports.
|
Note: you don't need to create websockets for the plain ports.
|
||||||
|
@ -374,6 +380,7 @@ lex = LEX.create({
|
||||||
, letsencrypt: LE.create(
|
, letsencrypt: LE.create(
|
||||||
// options
|
// options
|
||||||
{ configDir: './letsencrypt.config'
|
{ configDir: './letsencrypt.config'
|
||||||
|
, manual: true
|
||||||
|
|
||||||
, server: LE.productionServerUrl
|
, server: LE.productionServerUrl
|
||||||
, privkeyPath: LE.privkeyPath
|
, privkeyPath: LE.privkeyPath
|
||||||
|
|
|
@ -5,10 +5,10 @@ var challengeStore = require('./challenge-handlers');
|
||||||
var createSniCallback = require('./sni-callback').create;
|
var createSniCallback = require('./sni-callback').create;
|
||||||
var LE = require('letsencrypt');
|
var LE = require('letsencrypt');
|
||||||
|
|
||||||
function createAcmeResponder(obj, onRequest) {
|
function createAcmeResponder(lex, onRequest) {
|
||||||
|
|
||||||
function httpAcmeResponder(req, res) {
|
function httpAcmeResponder(req, res) {
|
||||||
if (LEX.debug) {
|
if (lex.debug) {
|
||||||
console.debug('[LEX] ', req.method, req.headers.host, req.url);
|
console.debug('[LEX] ', req.method, req.headers.host, req.url);
|
||||||
}
|
}
|
||||||
var acmeChallengePrefix = '/.well-known/acme-challenge/';
|
var acmeChallengePrefix = '/.well-known/acme-challenge/';
|
||||||
|
@ -20,10 +20,9 @@ function createAcmeResponder(obj, onRequest) {
|
||||||
|
|
||||||
var key = req.url.slice(acmeChallengePrefix.length);
|
var key = req.url.slice(acmeChallengePrefix.length);
|
||||||
|
|
||||||
obj.getChallenge({
|
// lex = { debug, webrootPath }
|
||||||
debug: LEX.debug || obj.debug
|
lex.getChallenge(lex, req.headers.host, key, function (err, val) {
|
||||||
}, req.headers.host, key, function (err, val) {
|
if (lex.debug) {
|
||||||
if (LEX.debug) {
|
|
||||||
console.debug('[LEX] GET challenge, response:');
|
console.debug('[LEX] GET challenge, response:');
|
||||||
console.debug('challenge:', key);
|
console.debug('challenge:', key);
|
||||||
console.debug('response:', val);
|
console.debug('response:', val);
|
||||||
|
@ -128,7 +127,7 @@ function lexHelper(obj, app) {
|
||||||
|
|
||||||
if (!obj.approveRegistration && LEX.defaultApproveRegistration) {
|
if (!obj.approveRegistration && LEX.defaultApproveRegistration) {
|
||||||
obj.approveRegistration = function (domain, cb) {
|
obj.approveRegistration = function (domain, cb) {
|
||||||
if (LEX.debug) {
|
if (obj.debug) {
|
||||||
console.debug('[LEX] auto register against staging server');
|
console.debug('[LEX] auto register against staging server');
|
||||||
}
|
}
|
||||||
cb(null, {
|
cb(null, {
|
||||||
|
@ -257,6 +256,7 @@ function LEX(obj, app) {
|
||||||
module.exports = LEX;
|
module.exports = LEX;
|
||||||
|
|
||||||
LEX.create = LEX;
|
LEX.create = LEX;
|
||||||
|
LEX.createServers = LEX;
|
||||||
LEX.setChallenge = challengeStore.set;
|
LEX.setChallenge = challengeStore.set;
|
||||||
LEX.getChallenge = challengeStore.get;
|
LEX.getChallenge = challengeStore.get;
|
||||||
LEX.removeChallenge = challengeStore.remove;
|
LEX.removeChallenge = challengeStore.remove;
|
||||||
|
|
Loading…
Reference in New Issue