-
How does Nuxt initiate cross-domain resource requests? How does nuxt+vue+axios configure proxy forwarding (nuxt.config.js) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
` API_SERVER = 'http://youguolocal.testin.cn', NODE_ENV = 'dev' } = process.env; module.exports = { axios: { proxy: true }, proxy: { '/dsp': { target: API_SERVER, onProxyRes(proxyRes) { proxyRes.headers['content-type'] = 'application/json'; } } }, '/ssp': { target: API_SERVER, onProxyRes(proxyRes) { proxyRes.headers['content-type'] = 'application/json'; } } } } } } } In this way, when we run the project, if there is a /ssp request link in the root directory, it will be forwarded to API_SERVER (the default setting is http://youguolocal.testin.cn). If there is no /ssp path in the interface, remember to configure the proxy Chinese pathRewrite: { '^/ssp': '/' // rewrite path } to rewrite the path. Then in the test environment, we may need to forward the API to the test environment. We can change the value of API_SERVER accordingly when starting the test environment, and set it in the package.json file "scripts": { "dev:test": "cross-env API_SERVER=http://youguo.test.testin.cn DEBUG=NUXT:* nuxt dev" } } |
Beta Was this translation helpful? Give feedback.
`
const {
API_SERVER = 'http://youguolocal.testin.cn',
NODE_ENV = 'dev'
} = process.env;
module.exports = {
axios: {
proxy: true
},
proxy: {
'/dsp': {
target: API_SERVER,
onProxyRes(proxyRes) {
proxyRes.headers['content-type'] = 'application/json';
} }
},
'/ssp': {
target: API_SERVER,
onProxyRes(proxyRes) {
proxyRes.headers['content-type'] = 'application/json';
} }
} }
} }
}
In this way, when we run the project, if there is a /ssp request link in the root directory, it will be forwarded to API_SERVER (the default setting is http://youguolocal.testin.cn). If there is…