如何为 angular 配置 proxy.config.json

how to config proxy.config.json for angular

我使用 proxy.config.json 进行 http 调用。

我的例子:

 "/api/countries/*": {
    "target": "http://localhost:8084/countries",
    "secure": false,
    "changeOrigin": true,
    "pathRewrite": {
      "^/api/countries": ""
    },
    "logLevel": "debug"
  }
}

我得打电话给http://localhost:8084/countries。 (工作正常)和 http://localhost:8084/countries/textParam

后者未被代理。它被重写为:/textParam

[HPM] 将路径从“/api/countries/textParam”重写为“/textParam”

并且 http.put-请求丢失了 textParam。

[HPM] PUT /api/countries/textParam ~> http://localhost:8084/countries

我找不到对我有帮助的文档。

我该如何增强我的配置?

感谢您的帮助。

你一定要试试, "target":"http://localhost:8084"

并尝试 /api/* 而不是 /api/countries/* .

请参考这个linkhttps://github.com/angular/angular-cli/wiki/stories-proxy