accept optional function to use next

This commit is contained in:
AJ ONeal 2016-08-10 22:23:31 -06:00
parent d9ff6bf4de
commit 1179dff734
1 changed files with 10 additions and 2 deletions

View File

@ -17,13 +17,21 @@ module.exports.create = function (le) {
}
log(le.debug, "created middleware");
return function () {
return function (_app) {
if (_app && 'function' !== typeof _app) {
throw new Error("use le.middleware() or le.middleware(function (req, res) {})");
}
var prefix = le.acmeChallengePrefix || '/.well-known/acme-challenge/';
return function (req, res, next) {
if (0 !== req.url.indexOf(prefix)) {
log(le.debug, "no match, skipping middleware");
next();
if (_app) {
_app(req, res, next);
}
else {
next();
}
return;
}