【问题标题】:Webpack / Angular CLI / Proxy forwardingWebpack / Angular CLI / 代理转发
【发布时间】:2017-06-20 12:52:09
【问题描述】:

我需要在 AngularCLI / Webpack env 中设置一个代理来将来自http://localhost:4200/rest 的请求转发到https://someserver.com/somepath/rest

首先,端点是 https 而不是 http。

其次,请求 url 可以是 http://localhost:4200/rest/foo...:4200/rest/bar 并且所有和任何在 '/rest' 之后的路径都需要映射到 https://someserver.com/somepath/rest/foo...com/somepath/rest/bar

下面的proxy.conf.json好像没有正确配置:

"/rest": {
    "target": "https://someserver.com",
    "changeOrigin": true,
    "ws": true,
    "pathRewrite": {
      "^/rest/": "/somepath/rest/"
    },
    "secure": false,
    "logLevel": "debug"
  }

应用开始于

ng serve --proxy-config proxy.conf.json --live-reload --host 0.0.0.0

谢谢!

【问题讨论】:

    标签: node.js angular angular-cli webpack-dev-server http-proxy-middleware


    【解决方案1】:

    你应该改变你的pathRewrite

     "/rest/": {
            "target": "https://someserver.com/somepath/rest/",
            "changeOrigin": true,
            "ws": true,
            "pathRewrite": {
              "^/rest/": "/"
            },
            "secure": false,
            "logLevel": "debug"
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-17
      • 2016-12-27
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2018-01-02
      相关资源
      最近更新 更多