diff --git a/lib/apis.js b/lib/apis.js index 7058167..2d1e659 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -27,7 +27,6 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { function isThisClientAllowedToUseThisPkg(myConf, clientUrih, pkgId) { var appApiGrantsPath = path.join(myConf.appApiGrantsPath, clientUrih); - console.log('sanity exists?', appApiGrantsPath); return fs.readFileAsync(appApiGrantsPath, 'utf8').then(function (text) { console.log('sanity', text); return text.trim().split(/\n/); @@ -57,6 +56,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { function loadRestHelper(myConf, pkgId) { var pkgPath = path.join(myConf.restPath, pkgId); + // TODO should not require package.json. Should work with files alone. return fs.readFileAsync(path.join(pkgPath, 'package.json'), 'utf8').then(function (text) { var pkg = JSON.parse(text); var deps = {}; @@ -85,6 +85,13 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { console.log('DEBUG pkgPath', pkgPath); myApp = express(); + myApp.use('/', function preHandler(req, res, next) { + req.originalUrl = req.originalUrl || req.url; + // "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello' + req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/'); + console.log('[prehandler] req.url', req.url); + next(); + }); // // TODO handle /accounts/:accountId //