首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack / Angular CLI / Proxy转发

Webpack / Angular CLI / Proxy转发
EN

Stack Overflow用户
提问于 2017-06-20 20:52:09
回答 1查看 282关注 0票数 0

我需要在AngularCLI / Webpack环境中设置一个代理,以便将请求从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似乎配置不正确:

代码语言:javascript
复制
"/rest": {
    "target": "https://someserver.com",
    "changeOrigin": true,
    "ws": true,
    "pathRewrite": {
      "^/rest/": "/somepath/rest/"
    },
    "secure": false,
    "logLevel": "debug"
  }

应用程序的启动方式为

代码语言:javascript
复制
ng serve --proxy-config proxy.conf.json --live-reload --host 0.0.0.0

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-20 22:56:01

您应该更改您的pathRewrite

代码语言:javascript
复制
 "/rest/": {
        "target": "https://someserver.com/somepath/rest/",
        "changeOrigin": true,
        "ws": true,
        "pathRewrite": {
          "^/rest/": "/"
        },
        "secure": false,
        "logLevel": "debug"
      }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44653599

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档