How to Modify the Request Path in a Node Express Proxy Setup?

16 Replies, 1634 Views

Hey there! If you're looking for a Node Express proxy change request path solution, you might wanna check out `express-http-proxy` as an alternative. It’s super easy to use and has a `proxyReqPathResolver` option that lets you modify the path dynamically. Here’s a snippet:

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

app.use('/api/v1', proxy('http://backend-server', {
proxyReqPathResolver: (req) => {
return req.url.replace('/api/v1', '/v2');
}
}));
```

This gives you more control over the path transformation. Plus, it’s lightweight and works great with Express.

Messages In This Thread



Users browsing this thread: 1 Guest(s)