【Azure Function】Function App门户上的Test Run返回错误:Failed to fetch - LuBu0505/My-Code GitHub Wiki

问题描述

在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 ()\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}

错误截图:

image.png

问题解答

从截图和错误信息来看,是因为无法获取到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 即可解决此问题。 image.png

参考资料

添加 CORS 功能 : https://docs.azure.cn/zh-cn/app-service/app-service-web-tutorial-rest-api#add-cors-functionality

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

⚠️ **GitHub.com Fallback** ⚠️