devServer: { proxy: [
// 例如將'localhost: 8080/api/xxx'代理到'http:www.baidu.com/api/xxx
{ context: ['/api'], target: 'http:www.baidu.com',//接口域名 changeOrigin: true, //如果是https需要配置該參數 secure: false, //如果接口跨域需要進行該配置 },
// 例如將'localhost: 8080/img/xxx'代理到'http:www.baidu.com/xxx
{
context: ['/img'], target: 'http:www.baidu.com',//接口域名 changeOrigin: true, //如果是https需要配置該參數 secure: false, //如果接口跨域需要進行該配置
pathRewrite: {//是指服務器把接口中api去掉,以免img這幾個字母加入到接口地址中
'^/img': '' }
},
] }
let base = ''; // 測試' if (process.env.NODE_ENV === "development") { base = "/api/move-server"; // 開發 } else if ( process.env.NODE_ENV === "production") { base = ''; // 線上 }