most basic middleware function
This commit is contained in:
parent
9ae3c7d6f6
commit
5ff91ec37e
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = function (le) {
|
||||
return function () {
|
||||
var prefix = le.acmeChallengePrefix; // /.well-known/acme-challenge/:token
|
||||
|
||||
return function (req, res, next) {
|
||||
if (0 !== req.url.indexOf(prefix)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
var key = req.url.slice(prefix.length);
|
||||
var hostname = req.hostname || (req.headers.host || '').toLowerCase().replace(/:*/, '');
|
||||
|
||||
// TODO tpl copy?
|
||||
le.challenger.getAsync(le, hostname, key).then(function (token) {
|
||||
if (!token) {
|
||||
res.status = 404;
|
||||
res.send("Error: These aren't the tokens you're looking for. Move along.");
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(token);
|
||||
}, function (/*err*/) {
|
||||
res.status = 404;
|
||||
res.send("Error: These aren't the tokens you're looking for. Move along.");
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue