From 841d6b3948271f88a0d913da5ed58b54873a6d7a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 11 Dec 2015 05:54:30 +0000 Subject: [PATCH] don't ignore .well-known (or any dot files) --- lib/package-server.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/package-server.js b/lib/package-server.js index f17ec66..8155e73 100644 --- a/lib/package-server.js +++ b/lib/package-server.js @@ -89,13 +89,18 @@ function loadPages(pkgConf, route, req, res, next) { if (!route._promise_app) { route._promise_app = new PromiseA(function (resolve, reject) { fs.exists(pkgpath, function (exists) { + var staticServer; + if (!exists) { reject(new Error("package is registered but does not exist")); return; } //console.log('[static mount]', pkgpath); - resolve(require('serve-static')(pkgpath)); + // https://github.com/expressjs/serve-static/issues/54 + // https://example.com/.well-known/acme-challenge/xxxxxxxxxxxxxxx + staticServer = require('serve-static')(pkgpath, { dotfiles: 'allow' }); + resolve(staticServer); }); }); } @@ -374,10 +379,27 @@ function mapToApp(opts, req, res, next) { return; } + // TODO .well-known can be an API (webfinger, letsencrypt, oauth3) + // or static (...???) + if (!router._re_api.test(req.url)) { //console.log('[static router]'); //console.log(router._re_api, req.url); - layerItUp(pkgConf, router, req, res, next); + layerItUp(pkgConf, router, req, res, function (err) { + if (err) { + next(err); + return; + } + + if (/\/\.well-known([\/?]|$)/.test(req.url)) { + console.log('[TODO] handle .well-known as API'); + // rewrite api as /api/org.ietf/.well-known ? + // pass through simply as /.well-known ? + // runApi(opts, router, req, res, next) + } + + next(); + }); return; }