This is the configuration
proxyTable: {
'/api': {
target: 'http://news-at.zhihu.com',
changeOrigin: true,
pathRewrite: {
'^/api': '/api'
}
}
}
Use axios to request data
You can run npm run dev directly, but you cannot get the api after packaging it and putting it on apache
Error reporting
Generally, it is deployed to the formal environment after building. As for what you said about putting it under Apache, the actual request for
/api/xxx
is also targeted at the Apache Server. So you need to get a rewrite (reverse proxy) for /api for ApacheYou can refer to nginx configuration:
You see that the proxyTable configuration is written on dev, which proves that this only applies to the dev environment. Essentially, a server dev-server is opened locally, and all requests are forwarded through here.
You have to run a node web service yourself and then use this in it
This configuration file can be written in a separate config file and referenced in it, and this situation will not occur