How to do a wildcard proxy with 3.0? #1003
-
|
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 |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.