gpt4 book ai didi

javascript - 我需要为 "Application Insights for web pages"遥测调用创建代理终结点(Azure 函数代理失败 CORS 选项调用)

转载 作者:行者123 更新时间:2023-12-02 08:32:35 25 4
gpt4 key购买 nike

我有一个 html 应用程序 Application Insights for web pages和 Azure 函数 API。 Application Insights 正在通过调用 https://dc.services.visualstudio.com/v2/track 发送遥测数据。我希望此流量经过以下网址之一:

  • 我的 API 上的网址(即 my-app.azurewebsites.net/telemetry)
  • 我要创建的其他 API 的网址(即 my-app-telemetry.azurewebsites.net/telemetry)
  • 有什么方法可以将自定义 URL 端点添加到 Azure 上的 Application Insights 中吗?

本质上,我需要在我的 API 中创建一个代理端点。我试过Azure Function Proxies ,但到目前为止还没有运气,我收到 HTTP 代码 400 - 错误请求。

更新,我尝试的 Azure Function 代理如下所示:

{
"$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 Function Proxy 现在也应该转发 CORS 调用。

在您的 Azure Function 模板中,它应该如下所示

"cors": {
"allowedOrigins": [], //this should be empty array
"supportCredentials": false
}

最佳答案

我最近也遇到了这个问题。结果发现 OPTIONS 请求没有通过默认的 azure 函数 CORS 设置进行代理。您看到的 400 来自 azure 函数,不允许您的来源。

简单修复:删除 CORS 设置下的所有条目,然后您就可以代理 OPTIONS 请求。

enter image description here

关于javascript - 我需要为 "Application Insights for web pages"遥测调用创建代理终结点(Azure 函数代理失败 CORS 选项调用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59546383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com