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

20 Replies, 1665 Views

Hey! I had the exact same problem last month. For node express proxy change request path, I used `http-proxy-middleware` with `pathRewrite`. Here’s a quick example:

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

app.use('/api', proxy({
target: 'http://your-server.com',
pathRewrite: { '^/api': '/v1' }, // changes /api to /v1
}));
```

This worked perfectly for me. If you need more control, you can even use a function in `pathRewrite` to dynamically modify the path.

Also, their docs are pretty detailed. Worth a look!

Messages In This Thread



Users browsing this thread: 1 Guest(s)