How to do a wildcard proxy with 3.0? #1003
Answered
by
leoc-22
SantoJambit
asked this question in
Q&A
|
With 2.x I had the following code: app.use(
"*",
createProxyMiddleware({
target: "http://localhost:4200",
changeOrigin: true,
})
);This would forward all unknown requests (not already handled by express) to a separate server. In 3.0, this always responds with the index page of http://localhost:4200, rather than the specific sub-page that was actually requested. I don't see how I can do this with 3.0. Nothing in the migration guide seems to point to anything like it. Thanks in advance |
Answered by
leoc-22
Nov 10, 2024
Replies: 1 comment 1 reply
|
just encountered this issue this week and my solution is to use in my use case, it was to proxy anything with app.use(
"/api",
createProxyMiddleware({
pathRewrite: (path) => path
target: "http://localhost:4200",
changeOrigin: true,
})
);you can probably also use: on: {
proxyReq: (proxyReq, req, res) => {}
}to get the path after the base url and attach to the target base url. |
1 reply
Answer selected by
SantoJambit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just encountered this issue this week and my solution is to use
pathRewriteto returnpath.in my use case, it was to proxy anything with
/api/*to the target url:you can probably also use:
to get the path after the base url and attach to the target base url.