vue2 在manifest.json的代码视图中 根节点中配置h5
"h5":{
"devServer" : {
"https" : false,
"proxy" : {
"/test": {
"target": "http://cash.trade.com/prod-api",
"changeOrigin": true,
"secure": false,
"pathRewrite": {
"^/test": "/"
}
},
"/prod": {
"target": "http://tradecash.com/prod-api",
"changeOrigin": true,
"secure": false,
"pathRewrite": {
"^/prod": "/"
}
}
}
}
}
vue3 在项目根目录下(即跟App.vue同级)建vite.config.js,这个文件会默认优先加载
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({
plugins: [
uni()
],
server: {
port: 3000,
proxy: {
'/prod': {
target: 'http://tradeshop.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/prod/, ''),
},
'/test': {
target: 'http://192.168.2.81:3000',
changeOrigin: true,
rewrite: path => path.replace(/^\/test/, ''),
}
}
}
})