天天看点

ant design pro webapi访问提示跨域的2种解决办法一、通过配置文件配置proxy.ts设置代理

一、通过配置文件配置proxy.ts设置代理

ant design pro webapi访问提示跨域的2种解决办法一、通过配置文件配置proxy.ts设置代理
在生产环境 代理是无法生效的

/**
 * 在生产环境 代理是无法生效的,所以这里没有生产环境的配置
 * The agent cannot take effect in the production environment
 * so there is no configuration of the production environment
 * For details, please see
 * https://pro.ant.design/docs/deploy
 */
export default {
  dev: {
    '/api/': {
      target: 'http://localhost:21021',
      changeOrigin: true,
      pathRewrite: { '^': '' },
    },
  },
  test: {
    '/api/': {
      target: 'https://preview.pro.ant.design',
      changeOrigin: true,
      pathRewrite: { '^': '' },
    },
  },
  pre: {
    '/api/': {
      target: 'your pre url',
      changeOrigin: true,
      pathRewrite: { '^': '' },
    },
  },
};      

二、package.json文件中增加代理

"proxy": "http://clean.bathon.cn:6565",