http-proxy-middleware
http-proxy-middleware copied to clipboard
[BUG] Path rewrite failed
Expected behavior
pathRewrite success
Actual behavior
pathRewrite failed
Setup
- http-proxy-middleware: 0.18.0
- server: express 4.15.4
proxy middleware configuration
var apiProxy = proxy({
target: 'http://example.com/',
pathRewrite: {'^/tetris/api/sentry/api/314/store/' : '/api/314/store/'},
changeOrigin: true
});
server mounting
var app = express();
app.use('/tetris/api/sentry/api/314/store/', apiProxy);
app.listen(3000);
Reason
I found in here, using req.url not req.path, then req.url = 'http://host.com/path/to/be' and the regex in pathRewriter will not match this, since regex=^\/tetris\/api\/sentry\/api\/314\/store\/.
If we could change req.url -> req.path, it will be matched.
probably a bug ?
I finally find that because I use SwitchyOmega to proxy a domain(eg. example.com) to 127.0.0.1:3000 , neither req.url nor req.originalUrl, they were http://example.com/path/xxxx, not desired /path/xxx. So maybe it's the problem about my usage.
But, if could you take this scenery into consideration ? use req.path or other variables firmly stand for the path, not depends on the usage?