How to use setting.host + '/api/sop/' in the online environment, and the local dev requests localhost:3000?
const instance = axios.create({
baseURL: setting.host + '/api/sop/',
timeout: 20000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
});
config
proxyTable: {
'/api': {
target: "http://127.0.0.1:3000",
changeOrigin: true,
pathRewrite: {
'^/api': ""
}
}
},
Using vue-resource, the theoretical idea is the same.
proxyTable
和nginx
的反向代理是一样的道理,拦截特定的url
, forward to other servers.You can configure an environment variable and determine which configuration to use by judging the environment variable
After setting up, in the npn run dev stage, if you access '/get/apple locally, the local server will help you access http://api.com:6688/get/apple to get the remote data, realizing the cross-domain function in disguise
Open config/index.js and add proxyTable attribute
module.exports = {
}
https://github.com/383514580/...