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

10 Replies, 2203 Views

Yo! I had this exact problem last week. You can use `http-proxy-middleware` like you mentioned. The key is the `pathRewrite` option. Here’s how I did it:

```javascript
const proxy = require('http-proxy-middleware');

app.use('/api', proxy({
target: 'http://your-target-server.com',
pathRewrite: { '^/api/v1': '/v2' }
}));
```
This will map `/api/v1/users` to `/v2/users`. Super clean and easy to implement. Hope this helps!

Messages In This Thread



Users browsing this thread: 1 Guest(s)