webpack 关于项目跨域设置以及nginx配置

74 阅读1分钟

项目中所在位置

image.png


    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api':{
        target:'https://www.baidu.com', // 你需要代理的地址
        secure: true, // 如果是https接口,需要配置这个参数,
        changeOrigin: true, // 是否跨域
        pathRewrite:{ '^/api': '' }
     },

    },

    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    autoOpenBrowser: false,
    errorOverlay: true,
    notifyOnErrors: true,
    poll: false, 
    

关于nginx配置遇到跨域,全局配置

Access-Control-Allow-Credentials:true

Access-Control-Allow-Headers:origin,x-requested-with,content-type

Access-Control-Allow-Methods:POST,GET,OPTIONS

Access-Control-Allow-Origin:*