correct urls
This commit is contained in:
		
							parent
							
								
									74fa3f2e14
								
							
						
					
					
						commit
						19ffff4fcd
					
				| @ -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; | ||||||
|             } |             } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user