correct urls

这个提交包含在:
AJ ONeal 2017-05-24 05:25:11 +00:00
父节点 74fa3f2e14
当前提交 19ffff4fcd
共有 2 个文件被更改,包括 9 次插入1 次删除

查看文件

@ -115,7 +115,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
require('oauthcommon').inject(_getOauth3Controllers, myApp/*, pkgConf, pkgDeps*/); require('oauthcommon').inject(_getOauth3Controllers, myApp/*, pkgConf, pkgDeps*/);
myApp.use('/', function preHandler(req, res, next) { myApp.use('/', function preHandler(req, res, next) {
req.originalUrl = req.originalUrl || req.url; req.walnutOriginalUrl = req.url;
// "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello' // "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello'
req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/'); req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/');
console.log('[prehandler] req.url', req.url); console.log('[prehandler] req.url', req.url);
@ -127,6 +127,13 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
return PromiseA.resolve(require(pkgPath).create({ return PromiseA.resolve(require(pkgPath).create({
etcpath: xconfx.etcpath etcpath: xconfx.etcpath
}/*pkgConf*/, pkgDeps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) { }/*pkgConf*/, pkgDeps/*pkgDeps*/, myApp/*myApp*/)).then(function (handler) {
myApp.use('/', function postHandler(req, res, next) {
req.url = req.walnutOriginalUrl;
console.log('[posthandler] req.url', req.url);
next();
});
localCache.pkgs[pkgId] = { pkg: pkg, handler: handler || myApp, createdAt: Date.now() }; localCache.pkgs[pkgId] = { pkg: pkg, handler: handler || myApp, createdAt: Date.now() };
return localCache.pkgs[pkgId]; return localCache.pkgs[pkgId];
}); });

查看文件

@ -235,6 +235,7 @@ module.exports.create = function (webserver, xconfx, state) {
// doesn't have /api url prefix // doesn't have /api url prefix
if (!/^\/api\//.test(req.url)) { if (!/^\/api\//.test(req.url)) {
console.log('[walnut/worker api] req.url', req.url);
res.send({ error: { message: "missing /api/ url prefix" } }); res.send({ error: { message: "missing /api/ url prefix" } });
return; return;
} }