vite
vite copied to clipboard
feat(proxy): add router to support dynamically set the target
Description
add router option to support dynamically set the target
Additional context
URL example: /dynamicProxy/localhost:9607/anotherApp
Configuration
server: {
proxy: {
'/dynamicProxy': {
target: 'http://localhost:9600',
router: (req) => {
const target = req.url.match(/\/dynamicProxy\/(.*?)\//)[1]
return `http://${target}`
},
rewrite: (path) => path.replace(/^\/dynamicProxy\/.*?\//, ''),
changeOrigin: true,
}
}
}
What is the purpose of this pull request?
- [ ] Bug fix
- [X] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [X] Read the Contributing Guidelines.
- [X] Read the Pull Request Guidelines and follow the PR Title Convention.
- [X] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [X] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123). - [X] Ideally, include relevant tests that fail without this PR but pass with it.
Run & review this pull request in StackBlitz Codeflow.
Thanks for the PR. There is another PR implementing the same but also supporting a more extensive API here:
- https://github.com/vitejs/vite/pull/2808
It seems we never ended up discussing this one in a team meeting. I'll add it to the Team board. Just to set expectations, it may take us a few weeks as we just met today.
related: #13932 (The difference is that #13968 supports changing the target but #13932 doesn't)
Have any news about this PR?
That would be very nice to have this feature. I wonder what are the workaround in the current situation. I have see one custom plugin vite-plugin-proxy-middleware but didn't tested it yet.
This PR https://github.com/vitejs/vite/pull/2808 seems to be more developed.
any updates?