From 0696ba8084470c060d967d56fb2ffe08243cb820 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 20 May 2017 05:16:01 +0000 Subject: [PATCH] remove API prefix --- lib/apis.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 //