【发布时间】:2026-02-14 06:35:01
【问题描述】:
我有一个带有 Application Insights for web pages 和 Azure Function api 的 html 应用程序。 Application Insights 正在通过对 https://dc.services.visualstudio.com/v2/track 的调用发送遥测。我希望此流量通过以下网址之一:
- 我的 API 上的 URL(即 my-app.azurewebsites.net/telemetry)
- 我将创建的其他 API 的 URL(即 my-app-telemetry.azurewebsites.net/telemetry)
- 以某种方式将自定义 url 端点添加到我在 Azure 上的 Application Insights?
基本上,我需要在我的 API 中创建一个代理端点。我尝试了Azure Function Proxies,但到目前为止没有运气,我收到了 HTTP 代码 400 - 错误请求。
更新一下,我试过的 Azure Function Proxy 是这样的:
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"Application insights": {
"matchCondition": {
"route": "telemetry",
"methods": [
"GET",
"POST",
"OPTIONS"
]
},
"backendUri": "https://dc.services.visualstudio.com/v2/track",
"responseOverrides": {
"response.headers.Access-Control-Allow-Origin": "*"
}
}
}
}
更新
@naile 提供了一个解决方案。 Azure 函数代理默认不代理 CORS 调用。您应该导航到“平台功能”=>“CORS”并删除您在那里看到的所有内容(请参阅已接受答案中的屏幕截图)。
默认包含
"https://functions.azure.com",
"https://functions-staging.azure.com",
"https://functions-next.azure.com"
删除这些,Azure 函数代理现在也应该转发 CORS 调用。
在你的 Azure Function 模板中,它应该是这样的
"cors": {
"allowedOrigins": [], //this should be empty array
"supportCredentials": false
}
【问题讨论】:
-
请问是什么目的?那我大概可以给出更好的答案
-
@Peter Bons 我现在可以使用 Application Insights,但我应该避免从浏览器调用 3-rd 方 url。
标签: javascript azure azure-application-insights custom-url