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

20 Replies, 1566 Views

Hey! I’ve been working on something similar. 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': '' }, // removes /api
}));
```

This should help you strip or modify the path. If you need more advanced stuff, you can even use a function in `pathRewrite` to handle dynamic changes.

Also, their GitHub page has a ton of examples. Definitely worth checking out!



Users browsing this thread: 1 Guest(s)