This commit is contained in:
aj 2017-08-16 19:47:51 +00:00
parent dae941323b
commit babfb6b38b
2 changed files with 12 additions and 2 deletions

View File

@ -257,7 +257,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
// let's go with this one for now and the api can choose to scope or not to scope // let's go with this one for now and the api can choose to scope or not to scope
pkgDeps.memstore = apiFactories.memstoreFactory.create(pkgId); pkgDeps.memstore = apiFactories.memstoreFactory.create(pkgId);
console.log('DEBUG pkgPath', pkgPath);
myApp = express(); myApp = express();
myApp.handlePromise = promisableRequest; myApp.handlePromise = promisableRequest;
myApp.handleRejection = rejectableRequest; myApp.handleRejection = rejectableRequest;
@ -319,7 +318,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var _twilio; var _twilio;
var _get_response; var _get_response;
myApp.use('/', function preHandler(req, res, next) { myApp.use('/', function preHandler(req, res, next) {
//if (xconfx.debug) { console.log('[api.js] loading handler prereqs'); }
return getSiteConfig(clientUrih).then(function (siteConfig) { return getSiteConfig(clientUrih).then(function (siteConfig) {
//if (xconfx.debug) { console.log('[api.js] loaded handler site config'); }
Object.defineProperty(req, 'getSiteMailer', { Object.defineProperty(req, 'getSiteMailer', {
enumerable: true enumerable: true
, configurable: false , configurable: false
@ -722,15 +723,18 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
etcpath: xconfx.etcpath etcpath: xconfx.etcpath
}/*pkgConf*/, pkgDeps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) { }/*pkgConf*/, pkgDeps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) {
//if (xconfx.debug) { console.log('[api.js] got handler'); }
myApp.use('/', function postHandler(req, res, next) { myApp.use('/', function postHandler(req, res, next) {
req.url = req._walnutOriginalUrl; req.url = req._walnutOriginalUrl;
next(); next();
}); });
localCache.pkgs[pkgId] = { pkgId: pkgId, pkg: pkg, handler: handler || myApp, createdAt: Date.now() }; localCache.pkgs[pkgId] = { pkgId: pkgId, pkg: pkg, handler: handler || myApp, createdAt: Date.now() };
pkgLinks.forEach(function (pkgLink) { pkgLinks.forEach(function (pkgLink) {
localCache.pkgs[pkgLink] = localCache.pkgs[pkgId]; localCache.pkgs[pkgLink] = localCache.pkgs[pkgId];
}); });
return localCache.pkgs[pkgId]; return localCache.pkgs[pkgId];
}); });
}); });
@ -773,7 +777,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
return function (req, res, next) { return function (req, res, next) {
cors(req, res, function () { cors(req, res, function () {
if (xconfx.debug) { console.log('[api.js] post cors'); } //if (xconfx.debug) { console.log('[api.js] after cors'); }
// Canonical client names // Canonical client names
// example.com should use api.example.com/api for all requests // example.com should use api.example.com/api for all requests
@ -835,6 +839,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
// TODO cache permission (although the FS is already cached, NBD) // TODO cache permission (although the FS is already cached, NBD)
var promise = isThisClientAllowedToUseThisPkg(xconfx, clientUrih, pkgId).then(function (yes) { var promise = isThisClientAllowedToUseThisPkg(xconfx, clientUrih, pkgId).then(function (yes) {
//if (xconfx.debug) { console.log('[api.js] azp is allowed?', yes); }
if (!yes) { if (!yes) {
notConfigured(req, res); notConfigured(req, res);
return null; return null;
@ -852,14 +857,17 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
if (!localCache.rests[pkgId]) { if (!localCache.rests[pkgId]) {
//return doesThisPkgExist //return doesThisPkgExist
//if (xconfx.debug) { console.log('[api.js] before rest handler'); }
return loadRestHandler(xconfx, clientUrih, pkgId).then(function (myHandler) { return loadRestHandler(xconfx, clientUrih, pkgId).then(function (myHandler) {
if (!myHandler) { if (!myHandler) {
//if (xconfx.debug) { console.log('[api.js] not configured'); }
notConfigured(req, res); notConfigured(req, res);
return; return;
} }
localCache.rests[pkgId] = { handler: myHandler.handler, createdAt: now }; localCache.rests[pkgId] = { handler: myHandler.handler, createdAt: now };
if (!hasBeenHandled) { if (!hasBeenHandled) {
//if (xconfx.debug) { console.log('[api.js] not configured'); }
myHandler.handler(req, res, next); myHandler.handler(req, res, next);
} }
}); });

View File

@ -218,6 +218,8 @@ function attachOauth3(req, res, next) {
Object.defineProperty(req, 'oauth3', {configurable: false, writable: false}); Object.defineProperty(req, 'oauth3', {configurable: false, writable: false});
next(); next();
}, function (err) { }, function (err) {
console.error('[walnut] lib/oauth3 error:');
console.error(err);
res.send(err); res.send(err);
}); });
} }