From babfb6b38beac1d284cfae2f064c5fd8e196a151 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 16 Aug 2017 19:47:51 +0000 Subject: [PATCH] logging --- lib/apis.js | 12 ++++++++++-- lib/oauth3.js | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/apis.js b/lib/apis.js index c426c88..4068e0b 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -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); } }); diff --git a/lib/oauth3.js b/lib/oauth3.js index 39440ab..fc8ea59 100644 --- a/lib/oauth3.js +++ b/lib/oauth3.js @@ -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); }); }