Angular CLI和http-proxy-middleware是否可能攔截/代理調用外部URL,如Azure功能或Firebase功能等無雲服務器功能?Angular CLI HTTP代理雲功能配置
例如,針對基於外部雲的功能URL(例如https://foobar.azurewebsites.net/api/SampleHttpFunction?code=123ABC456XYZ==
),您將如何設置proxy.conf.json
來攔截此URL /路徑?
以下配置已成功攔截HTTP請求(爲了開發目的,target
已設置爲本地運行的雲功能localhost端口)。角度應用程序使用命令"ng serve --proxy-config proxy.conf.json --open"
開始。
{
"/api": {
"target": "http://localhost:1234",
"secure": false
}
}
{
"foobar.azurewebsites.net/api": {
"target": "http://localhost:1234",
"secure": false
}
}
{
"**/api": {
"target": "http://localhost:1234",
"secure": false
}
}
的HttpClient
調用https://foobar.azurewebsites.net/api/SampleHttpFunction?code=123ABC456XYZ==
任何這些配置還是到生產的雲功能的URL,而不是http://localhost:1234/api
。
更新:每我使用multiple entry configuration與ng serve --proxy-config proxy.conf.js --open
啓動應用程序嘗試了建議,但它仍然無法趕上HTTP調用:
const PROXY_CONFIG = [{
context: [
"/api",
"**/api",
"**/api/*",
"https://foobar.azurewebsites.net/api/",
"foobar.azurewebsites.net/api/",
"foobar.azurewebsites.net/api/*",
"*foobar.azurewebsites.net/api"
],
target: "http://localhost:1234",
secure: false
}]
module.exports = PROXY_CONFIG;
謝謝你的任何幫助,您可以提供!
我嘗試使用'proxy.conf.js'多項配置,如你所建議的一些模式,並以'ng serve --proxy-config proxy.conf.js --open'開頭,但不幸的是它不行。 HTTP調用仍然會轉到生成azure函數的URL。這聽起來像配置需要額外的選項來查看HTTP調用的完整URL。這也將是關於捕捉域名/來源。 –