allow multiple pages too

This commit is contained in:
AJ ONeal 2015-12-02 12:42:23 +00:00
parent 760f00af35
commit 8cc7234d64
1 changed files with 14 additions and 19 deletions

View File

@ -62,18 +62,18 @@ function compileVhosts(vhostsMap) {
return results; return results;
} }
function loadPages(pkgConf, route, req, res, next) { function loadPages(pkgConf, packagedPage, req, res, next) {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var pkgpath = path.join(pkgConf.pagespath, (route.app.package || route.app.id), (route.app.version || '')); var pkgpath = path.join(pkgConf.pagespath, (packagedPage.package || packagedPage.id), (packagedPage.version || ''));
// TODO special cases for /.well_known/ and similar (oauth3.html, oauth3.json, webfinger, etc) // TODO special cases for /.well_known/ and similar (oauth3.html, oauth3.json, webfinger, etc)
function handlePromise(p) { function handlePromise(p) {
p.then(function (app) { p.then(function (app) {
app(req, res, next); app(req, res, next);
route._app = app; packagedPage._page = app;
}, function (err) { }, function (err) {
console.error('[App Promise Error]'); console.error('[App Promise Error]');
next(err); next(err);
@ -81,13 +81,13 @@ function loadPages(pkgConf, route, req, res, next) {
} }
if (staticHandlers[pkgpath]) { if (staticHandlers[pkgpath]) {
route._app = staticHandlers[pkgpath]; packagedPage._page = staticHandlers[pkgpath];
route._app(req, res, next); packagedPage._page(req, res, next);
return; return;
} }
if (!route._promise_app) { if (!packagedPage._promise_page) {
route._promise_app = new PromiseA(function (resolve, reject) { packagedPage._promise_page = new PromiseA(function (resolve, reject) {
fs.exists(pkgpath, function (exists) { fs.exists(pkgpath, function (exists) {
if (!exists) { if (!exists) {
reject(new Error("package '" + pkgpath + "' is registered but does not exist")); reject(new Error("package '" + pkgpath + "' is registered but does not exist"));
@ -100,7 +100,7 @@ function loadPages(pkgConf, route, req, res, next) {
}); });
} }
handlePromise(route._promise_app); handlePromise(packagedPage._promise_page);
} }
function getApi(pkgConf, pkgDeps, packagedApi) { function getApi(pkgConf, pkgDeps, packagedApi) {
@ -194,7 +194,7 @@ function layerItUp(pkgConf, router, req, res, next) {
// i.e. oauth3.html isn't in *your* app but you may use it and want it mounted at /.well-known/oauth3.html // i.e. oauth3.html isn't in *your* app but you may use it and want it mounted at /.well-known/oauth3.html
// or perhaps some dynamic content (like application cache) // or perhaps some dynamic content (like application cache)
function nextify(err) { function nextify(err) {
var route; var packagedPage;
nexti += 1; nexti += 1;
if (err) { if (err) {
@ -205,24 +205,19 @@ function layerItUp(pkgConf, router, req, res, next) {
// shortest to longest // shortest to longest
//route = packages.pop(); //route = packages.pop();
// longest to shortest // longest to shortest
route = router.packages[nexti]; packagedPage = router.packagedPages[nexti];
if (!route) { if (!packagedPage) {
next(); next();
return; return;
} }
if (!route.app) { if (packagedPage._page) {
// new Error("no Static App is registered for the specified path") packagedPage._page(req, res, nextify);
nextify();
return;
}
if (route._app) {
route._app(req, res, nextify);
return; return;
} }
// could attach to req.{ pkgConf, pkgDeps, Services} // could attach to req.{ pkgConf, pkgDeps, Services}
loadPages(pkgConf, route, req, res, next); loadPages(pkgConf, packagedPage, req, res, next);
} }
nextify(); nextify();