Webpack / Angular CLI / 代理转发

Webpack / Angular CLI / Proxy forwarding

我需要在 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

谢谢!

你应该改变你的 pathRewrite

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