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

10 Replies, 1824 Views

Hey! I’ve been using `http-proxy-middleware` for a while now, and it’s perfect for this. You can use the `pathRewrite` option to modify the request path dynamically. Here’s a simple example:

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

app.use('/api', proxy({
target: 'http://your-target-server.com',
pathRewrite: { '^/api/v1/users': '/v2/users' }
}));
```
This will change `/api/v1/users` to `/v2/users`. Super straightforward!

Messages In This Thread



Users browsing this thread: 1 Guest(s)