fix getChallenge (missing webrootPath) and update examples

This commit is contained in:
AJ ONeal 2016-02-12 21:28:23 -05:00
parent d1375aceb0
commit 6e0ba823d2
2 changed files with 15 additions and 8 deletions

View File

@ -171,7 +171,6 @@ Let's say you want to redirect all http to https.
var http = require('http');
var https = require('https');
var LEX = require('letsencrypt-express');
var LE = require('letsencrypt');
var lex = LEX.create({
configDir: __dirname + '/letsencrypt.config'
@ -184,6 +183,7 @@ var lex = LEX.create({
}
});
http.createServer(LEX.createAcmeResponder(lex, function redirectHttps(req, res) {
res.setHeader('Location', 'https://' + req.headers.host + req.url);
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));
```
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
Note: you don't need to create websockets for the plain ports.
@ -374,6 +380,7 @@ lex = LEX.create({
, letsencrypt: LE.create(
// options
{ configDir: './letsencrypt.config'
, manual: true
, server: LE.productionServerUrl
, privkeyPath: LE.privkeyPath

View File

@ -5,10 +5,10 @@ var challengeStore = require('./challenge-handlers');
var createSniCallback = require('./sni-callback').create;
var LE = require('letsencrypt');
function createAcmeResponder(obj, onRequest) {
function createAcmeResponder(lex, onRequest) {
function httpAcmeResponder(req, res) {
if (LEX.debug) {
if (lex.debug) {
console.debug('[LEX] ', req.method, req.headers.host, req.url);
}
var acmeChallengePrefix = '/.well-known/acme-challenge/';
@ -20,10 +20,9 @@ function createAcmeResponder(obj, onRequest) {
var key = req.url.slice(acmeChallengePrefix.length);
obj.getChallenge({
debug: LEX.debug || obj.debug
}, req.headers.host, key, function (err, val) {
if (LEX.debug) {
// lex = { debug, webrootPath }
lex.getChallenge(lex, req.headers.host, key, function (err, val) {
if (lex.debug) {
console.debug('[LEX] GET challenge, response:');
console.debug('challenge:', key);
console.debug('response:', val);
@ -128,7 +127,7 @@ function lexHelper(obj, app) {
if (!obj.approveRegistration && LEX.defaultApproveRegistration) {
obj.approveRegistration = function (domain, cb) {
if (LEX.debug) {
if (obj.debug) {
console.debug('[LEX] auto register against staging server');
}
cb(null, {
@ -257,6 +256,7 @@ function LEX(obj, app) {
module.exports = LEX;
LEX.create = LEX;
LEX.createServers = LEX;
LEX.setChallenge = challengeStore.set;
LEX.getChallenge = challengeStore.get;
LEX.removeChallenge = challengeStore.remove;