【Azure Function】Function App门户上的Test/Run返回错误:Failed to fetch
问题描述
在Azure Function的Code + Test页面上,点击 Test/Run 按钮无法成功。
错误信息:
Error: {"message":"Failed to fetch","stack":"TypeError: Failed to fetch\n at https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:23007\n at https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:23228\n at Ge (https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:7620)\n at https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:9566\n at Array.forEach (<anonymous>)\n at https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:9554\n at Object.Ge (https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:113:7620)\n at M (https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:59:2016)\n at P (https://portal.azure.cn/Content/Dynamic/cgORG6hTIVe1.js:59:1847)","isError":true}
错误截图:
问题解答
从截图和错误信息来看,是因为无法获取到js文件所以报错failed to fetch at https://portal.azure.cn/content/dynamic/sdlblohddxjx.js。并且也显示了CORS 警告消息。
Running your function in portal requires the app to explicitly accept requests from https://portal.azure.cn. This is known as cross-origin resource sharing (CORS).Configure CORS to add https://portal.azure.cn to allowed origins.
所以根据信息提示,进入 API --> CORS 页面,添加 Allowed Origins为 https://portal.azure.cn 即可解决此问题。
参考资料
添加 CORS 功能 : https://docs.azure.cn/zh-cn/app-service/app-service-web-tutorial-rest-api#add-cors-functionality
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2023-02-13 【Azure 事件中心】通过 az rest --method get 如何获得Event Hub Entity 级的统计指标