"/api/*": {
"target": "https://localhost:8000/api",
"secure": false,
"logLevel": "debug",
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true
}
请提供此代码片段中每个功能的详细使用
谢谢你的帮助
"/api/*": {
"target": "https://localhost:8000",
"secure": false,
"logLevel": "debug",
"pathRewrite": {
"^/api": ""
},
"changeOrigin": true
}
-
target:"api/*"
:
所有请求均发送至/api/
您的申请中的内容将被转发至target": "https://localhost:8000/api
-
"secure": false,
:
运行在 HTTPS 上的后端服务器
默认情况下不接受无效证书。如果你想,
你需要设置secure: false
.
-
"logLevel": "debug"
帮助调试您的代理是否
工作正常,您还可以添加 logLevel 选项
如下: logLevel 的可能选项包括debug
, info
,
warn
, error
, and silent
(默认为信息)。
-
"pathRewrite": { "^/api": "" },
pathRewrite 设置表示如果路径匹配^/api
(即,如果它以 /api 开头),则用空字符串重写该部分(即,将其从路径中删除),因此所有请求https://localhost:8000/api
将会去https://localhost:8000
-
"changeOrigin": true
:如果您需要访问不在本地主机上的后端,或者当您在后端使用某些虚拟代理(例如配置了 Apache2)时,请将其设置为 true。
proxy options https://github.com/nodejitsu/node-http-proxy#options该包中提供的内容来自底层node-http-proxy https://webpack.js.org/configuration/dev-server/#devserver-proxy
代理支持可能会帮助您摆脱一些CORS https://en.wikipedia.org/wiki/Cross-origin_resource_sharing开发阶段可能会出现异常,但客户端应用程序对这些异常无能为力。服务器必须配置为接受应用程序的请求。
I want to add CORS support to my server https://enable-cors.org/server.html
NOTE: The proxy
配置旨在通过运行开发服务器时代理调用ng serve
。跑完之后ng build
您负责网络服务器及其配置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)