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

16 Replies, 1329 Views

I feel you on the Node Express proxy change request path struggle! I ended up using a custom middleware before the proxy to modify the path. Something like this:

```javascript
app.use('/api/v1', (req, res, next) => {
req.url = req.url.replace('/api/v1', '/v2');
next();
});

app.use('/api/v1', createProxyMiddleware({ target: 'http://backend-server' }));
```

This way, you can do any crazy logic you want before the request hits the proxy. It’s a bit manual, but super flexible.

Messages In This Thread



Users browsing this thread: 1 Guest(s)