current position:Home>vue. config. Understanding of agent in JS

vue. config. Understanding of agent in JS

2022-04-29 17:13:49aliven1

.env.dev

NODEV_ENV='dev'
VUE_APP_BASEURL='/api'

.env.production

NODEV_ENV='production'
VUE_APP_BASEURL='https://test.bgo.com.cn'

vue.config.js Medium serve

module.exports = defineConfig({
    
  publicPath:'',
  devServer:{
    
    proxy:{
    
      [process.env.VUE_APP_BASEURL]: {
     // Intercept with api Path at the beginning 
        target: 'https://bimtalktest.bimgo.com.cn', //  Proxy interface address 
        changeOrigin: true, // Whether to enable cross domain 
        pathRewrite:{
    
          ['^'+process.env.VUE_APP_BASEURL]:''// rewrite api Prefix 
        }
      }
    }
  },
  lintOnSave:false,
  transpileDependencies: true
})

analysis :

development environment process.env.VUE_APP_BASEURL===‘/api’
By interface :main/api/ViewPointMessages For example
1./api Will be spliced to the route
2. With /api Initial api Will hit the agent , Avoid cross domain
3./api Will hit the route rewrite in the proxy , hold /api Reset to empty , Rewrite first , Re agency . The proxy address is +

copyright notice
author[aliven1],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291523013812.html

Random recommended