proxy configuration

Table of contents

1. Separate configuration file proxy.js

2. Referenced in vue.config.js


1. Separate configuration file proxy.js

/**
 * Created on 2023/1/16
 *  proxy 配置
 */

const httpsRE = /^https:\/\//;

/**
 * Generate proxy
 * @param list
 */

 const createProxy = function(list = []) {
   const ret = {};
   for (const [prefix, target] of list) {
     const isHttps = httpsRE.test(target);

     ret[prefix] = {
       target: target,
       changeOrigin: true,
       ws: true,
       pathRewrite: {},
       ...(isHttps ? { secure: false } : {}),
     };
   }
   return ret;
 }


module.exports = {
  createProxy
};

2. Referenced in vue.config.js

// 配置代理
const {createProxy} = require('../build/proxy');


// url
const URL = 'https://********.com';
const PROXY = [
  ["/admin",URL],
  ["/product",URL],
  ["/brand",URL]
]




// 代理
proxyTable: createProxy(PROXY),

Guess you like

Origin blog.csdn.net/qq_40963664/article/details/128704360