之前我在Angular中使用"proxy.conf.json“来代理http请求,它工作得很好。现在我想让代理urls成为动态的,我已经为它创建了一个在Angular Wiki (https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md)中提到的"proxy.conf.js“,并添加了以下内容:
const PROXY_CONFIG = [
{
context: [
"/api/*"
],
target: "https://example.com/",
logLevel: "debug",
secure: false,
changeOrigin: true
},
{
context: [
"/login/*"
],
target: "https://example1.com/",
logLevel: "debug",
secure: false,
changeOrigin: true
}
]
module.exports = PROXY_CONFIG;在"package.json“中,我添加了以下内容:
"start-dev": "ng serve --proxy-config proxy.conf.js",但是当我运行这个脚本"npm run start-dev“时,它没有从"proxy.conf.js”文件中读取,尽管它显示"Proxy created“。
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
10% building 3/3 modules 0 active[HPM] Proxy created: [ '/login/*' ] -> https://example1.com/url仍然指向"http://localhost:4200/“,而不是向"https://example.com/”发出http请求。

有没有人能告诉我这里有什么遗漏。
发布于 2019-02-11 00:39:39
在您的代理配置中,上下文模式是/login/*,但是,根据您的控制台输出,实际的请求只是/login,没有尾随组件。
因此,该代理规则das不匹配,并且开发服务器没有用于此的本地资源,因此以404回答。
您可以更改上下文,也可以为/login添加第二个条目。
https://stackoverflow.com/questions/54617766
复制相似问题