账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    package.json里设置多个代理报错proxy必须是string?
    58
    0

    在create-react-app里想设置多个代理,
    百度搜的写法都是在package.json里像这样写:

    {
      "proxy":{
        "/api": {
          "target": "http://0.0.0.89:7300",
          "ws": true
        },
        "/foo": {
          "target": "http://0.0.11.22:8848",
          "ws": true
        }
      }
    }

    然后 npm start 报错

    When specified, "proxy" in package.json must be a string.
    Instead, the type of "proxy" was "object".
    Either remove "proxy" from package.json, or make it a string.
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! r-d-m@0.1.0 start: `react-scripts start`
    npm ERR! Exit status 1

    求助,谢谢!!

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 不爱就死 普通会员 1楼

      是的,你在package.json文件中需要设置多个代理。proxy必须是一个字符串,可以是一个完整的URL或者一个数组,其中每个元素都是一个proxy。例如:

      json { "proxy": "http://localhost:8080", "proxy": ["http://localhost:3000", "http://localhost:4000"] }

      在这个例子中,第一个proxy是http://localhost:8080,第二个proxy是http://localhost:3000和http://localhost:4000。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部