拓荒
拓荒
  • 发布:2019-06-03 08:58
  • 更新:2020-08-30 18:43
  • 阅读:8008

manifest配置文件 devServer中的proxy,怎么设置多个代理,按照webpack官网配置报错

分类:uni-app

manifest配置文件 devServer中的proxy设置一个没有问题,如下:

"proxy": {  
        "/api": {  
                "target": "http://www.xxx.com",  
                "changeOrigin": true  
       }  
}

但是按照wepback官网配置多个编译的时候会报错。代码如下:

"proxy": [{  
      "context": ["/auth", "/api"],  
      "target": "http://www.xxx.com",  
      "changeOrigin": true  
 }]

错误信息如下:
When specified, "proxy" in package.json must be a string or an object.
Instead, the type of "proxy" was "object".
Either remove "proxy" from package.json, or make it an object.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tfw@0.1.0 dev:h5: cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tfw@0.1.0 dev:h5 script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2019-06-03 08:58 负责人:无 分享
已邀请:
7***@qq.com

7***@qq.com

它说的很清楚 When specified, "proxy" in package.json must be a string or an object. 当你指定proxy属性的时候,它必须是个对象 传array 肯定不认。 那么简单的写多个的话 可以类似这样

      "proxy": {  
            "/api": {  
                "target": "http://localhost:8902"  
            },  
            "/user": {  
                "target": "http://localhost:8902"  
            }  
        }
5***@qq.com

5***@qq.com

api改个api1都不行。

该问题目前已经被锁定, 无法添加新回复