-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proxy root url #3588
Comments
Your config is simply wrong. https://cli.vuejs.org/config/#devserver-proxy
|
This config will not proxy the root request.. here is my config: devServer: {
index: '',
host: process.env.SERVE_DOMAIN,
port: process.env.SERVE_PORT,
proxy: {
'^/': {
target: process.env.APP_URL,
ws: true,
changeOrigin: true,
},
},
}, problem is when I open http://SERVE_DOMAIN:SERVE_PORT (i.e. http://localhost:8080 ) dev server returns: instead of pass proxy to APP_URL If you want to proxy this request too, you need to pass vue-cli don't allow to pass context function, that's the problem EDIT: |
@padinko @LinusBorg I have the same issue. Due to iterative migration from I can't just convert whole app to SPA (it will take a lot of time) and some pages still handled by express. I've tried a lot of options and nothing helps |
@padinko Solved it this way (for now) const proxyMiddleware = require('http-proxy-middleware')
const PROXY = 'http://localhost:3000'
module.exports = {
devServer: {
index: '',
serveIndex: false,
historyApiFallback: false,
progress: false,
proxy: {
'^/': {
target: PROXY,
ws: false,
changeOrigin: true
}
},
staticOptions: {
redirect: false
},
after: app => app.use('/', proxyMiddleware(PROXY))
},
} Not the best way but at least it works fine in my case |
The workaround suggested by @probil no longer appears to work. If I create a webpack config with the following and run with webpack-dev-server everything is fine But trying to do the same in vue.config.js it's broken. module.exports = {
devServer: {
index: '',
proxy: {
context: () => true,
target: 'http://localhost:60171'
}
}
} Edit: Tested with vue-cli 4.0.0-rc.7, no good there either I got the setup I required making use of https://github.com/deraw/vue-cli-plugin-proxy Massive thanks to @deraw |
The problem seems coming from function mayProxy (pathname) {
...
- return !(isPublicFileRequest || isWdsEndpointRequest)
+ return !(isWdsEndpointRequest)
} and using the following in devServer: {
proxy: {
'/': {
target: 'http://localhost:8000'
}
}
} works fine for root path proxying |
I guess the way things are now, it's impossible to override Would it be feasible to have an additional option, say,
so Another solution is to check if |
this is not working |
any idea? |
module.exports = {
//...
devServer: {
index: '', // specify to enable root proxying
host: '...',
contentBase: '...',
proxy: {
context: () => true,
target: 'http://localhost:1234'
}
}
}; See more: https://webpack.js.org/configuration/dev-server/#devserverproxy |
Issue opened in 2019 and still no solution? |
What problem does this feature solve?
devServer.proxy cannot be used to proxy root requests now. It is very usefull when your vue app is under some php project.
What does the proposed API look like?
Webpack DevServer can be set to proxy root requests too: https://webpack.js.org/configuration/dev-server/#devserverproxy
with this config:
but now this config throw error:
When `proxy` in package.json is an object, each `context` object must have a `target` property specified as a url string
The text was updated successfully, but these errors were encountered: