How to Modify the Request Path in a Node Express Proxy? Need Help with 'node express proxy change request path'![/b

10 Replies, 2210 Views

Hey! I’ve been in the same boat before. You can totally use `http-proxy-middleware` for this. Just set up a custom `pathRewrite` function to dynamically change the request path.

Here’s a quick snippet:
```javascript
const { createProxyMiddleware } = require('http-proxy-middleware');

app.use('/api', createProxyMiddleware({
target: 'http://your-target-server.com',
pathRewrite: (path, req) => {
return path.replace('/api/v1', '/v2');
}
}));
```
This should help you with the node express proxy change request path issue. Let me know if you need more details!

Messages In This Thread



Users browsing this thread: 1 Guest(s)