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
pkgDeps.memstore = apiFactories.memstoreFactory.create(pkgId);
console.log('DEBUG pkgPath', pkgPath);
myApp = express();
myApp.handlePromise = promisableRequest;
myApp.handleRejection = rejectableRequest;
@ -319,7 +318,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var _twilio;
var _get_response;
myApp.use('/', function preHandler(req, res, next) {
//if (xconfx.debug) { console.log('[api.js] loading handler prereqs'); }
return getSiteConfig(clientUrih).then(function (siteConfig) {
//if (xconfx.debug) { console.log('[api.js] loaded handler site config'); }
Object.defineProperty(req, 'getSiteMailer', {
enumerable: true
, configurable: false
@ -722,15 +723,18 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
etcpath: xconfx.etcpath
}/*pkgConf*/, pkgDeps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) {
//if (xconfx.debug) { console.log('[api.js] got handler'); }
myApp.use('/', function postHandler(req, res, next) {
req.url = req._walnutOriginalUrl;
next();
});
localCache.pkgs[pkgId] = { pkgId: pkgId, pkg: pkg, handler: handler || myApp, createdAt: Date.now() };
pkgLinks.forEach(function (pkgLink) {
localCache.pkgs[pkgLink] = localCache.pkgs[pkgId];
});
return localCache.pkgs[pkgId];
});
});
@ -773,7 +777,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
return function (req, res, next) {
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
// 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)
var promise = isThisClientAllowedToUseThisPkg(xconfx, clientUrih, pkgId).then(function (yes) {
//if (xconfx.debug) { console.log('[api.js] azp is allowed?', yes); }
if (!yes) {
notConfigured(req, res);
return null;
@ -852,14 +857,17 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
if (!localCache.rests[pkgId]) {
//return doesThisPkgExist
//if (xconfx.debug) { console.log('[api.js] before rest handler'); }
return loadRestHandler(xconfx, clientUrih, pkgId).then(function (myHandler) {
if (!myHandler) {
//if (xconfx.debug) { console.log('[api.js] not configured'); }
notConfigured(req, res);
return;
}
localCache.rests[pkgId] = { handler: myHandler.handler, createdAt: now };
if (!hasBeenHandled) {
//if (xconfx.debug) { console.log('[api.js] not configured'); }
myHandler.handler(req, res, next);
}
});

View File

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