[英]Debugging a Node.js Azure function
嗨,我正在嘗試在本地調試和開發一個簡單的 JavaScript timerTrigger 函數 azure 應用程序,但我遇到了問題。 我正在嘗試按照本教程進行操作: https : //docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
調查資料請提供以下信息:
我通過 Git 存儲庫處理了該應用程序,因此它也在我的本地機器上。
提供重現問題所需的步驟:
轉到函數應用程序的根級別並運行(通過 powershell): func host start --debug vscode
λ func host start --debug vscode %%%%%% %%%%%% @ %%%%%% @ @@ %%%%%% @@ @@@ %%%%%%%%%%% @@@ @@ %%%%%%%%%% @@ @@ %%%% @@ @@ %%% @@ @@ %% @@ %% %
[10/16/2017 6:54:48 PM] Host has been specialized Listening on http://localhost:7071/ Hit CTRL-C to exit... [10/16/2017 6:54:48 PM] Reading host configuration file 'C:\\Users\\xxxxxxxx\\code\\test-repos\\NodeRepo1\\host.json' [10/16/2017 6:54:48 PM] Host configuration file read: [10/16/2017 6:54:48 PM] { } [10/16/2017 6:54:48 PM] Loaded custom extension 'BotFrameworkConfiguration' [10/16/2017 6:54:48 PM] Loaded custom extension 'SendGridConfiguration' [10/16/2017 6:54:48 PM] Loaded custom extension 'EventGridExtensionConfig' [10/16/2017 6:54:48 PM] Generating 0 job function(s) [10/16/2017 6:54:48 PM] Starting Host (HostId=laptop2062-1189224982, Version=1.0.11232.0, ProcessId=8180, Debug=False, Attempt=0) [10/16/2017 6:54:48 PM] No job functions found. Try making your job classes and methods public. If you're using binding extensions (eg ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (eg config.UseServiceBus(), config.UseTimers(), etc.). [10/16/2017 6:54:48 PM] Job host started [10/16/2017 6:54:48 PM] Executing HTTP request: { [10/16/2017 6:54:48 PM] "requestId": "b2d45bf0-1947-4ad7-a9cd-cdfa469d04d2", [10/16/2017 6:54:48 PM] "method": "GET", [10/16/2017 6:54:48 PM] "uri": "/" [10/16/2017 6:54:48 PM] } [10/16/2017 6:54:48 PM] Executed HTTP request: { [10/16/2017 6:54:48 PM] "requestId": "b2d45bf0-1947-4ad7-a9cd-cdfa469d04d2", [10/16/2017 6:54:48 PM] "method": "GET", [10/16/2017 6:54:48 PM] "uri": "/", [10/16/2017 6:54:48 PM] "authorizationLevel": "Anonymous" [10/16/2017 6:54:48 PM] } [10/16/2017 6:54:48 PM] Response details: { [10/16/2017 6:54:48 PM] "requestId": "b2d45bf0-1947-4ad7-a9cd-cdfa469d04d2", [10/16/2017 6:54:48 PM] "status": "OK" [10/16/2017 6:54:48 PM] } launch.json for VSCode configured. Debugger listening on [::]:5858 [10/16/2017 6:54:51 PM] Executing HTTP request: { [10/16/2017 6:54:51 PM] "requestId": "9fe12a9e-446a-4c8e-90db-d0004ac42e31", [10/16/2017 6:54:51 PM] "method": "GET", [10/16/2017 6:54:51 PM] "uri": "/admin/functions/noderepo" [10/16/2017 6:54:51 PM] } [10/16/2017 6:54:51 PM] Executed HTTP request: { [10/16/2017 6:54:51 PM] "requestId": "9fe12a9e-446a-4c8e-90db-d0004ac42e31", [10/16/2017 6:54:51 PM] "method": "GET", [10/16/2017 6:54:51 PM] "uri": "/admin/functions/noderepo", [10/16/2017 6:54:51 PM] "authorizationLevel": "Anonymous" [10/16/2017 6:54:51 PM] } [10/16/2017 6:54:51 PM] Response details: { [10/16/2017 6:54:51 PM] "requestId": "9fe12a9e-446a-4c8e-90db-d0004ac42e31", [10/16/2017 6:54:51 PM] "status": "MethodNotAllowed" [10/16/2017 6:54:51 PM] }
在瀏覽器中訪問http://localhost:7071/admin/functions/noderepo
在查看我的計時器觸發器后,我得到:
<Error> <Message> The requested resource does not support http method 'GET'. </Message> </Error>
我嘗試在 URL 中用timerTrigger
和myTrigger
替換noderepo
, timerTrigger
仍然是一樣的。 我該如何調試?
執行 JavaScript 函數方法並在 VS Code 上中斷
我的index.js
是這樣的:
module.exports = function (context, myTimer) { var timeStamp = new Date().toISOString(); config.UseTimers(); if(myTimer.isPastDue) { context.log('JavaScript is running late!'); } context.log('JavaScript timer trigger function ran!', timeStamp); context.done(); };
很簡單....
您是否嘗試過運行新版本的 Azure 工具 cli?
npm install azure-functions-core-tools@core
新版本的 cli 是建立在 .NET 核心之上的,它是 x 平台的。 該架構不再依賴 Edge.js,而是將處理工作卸載到節點工作器。 cli 工作程序始終以 --inspect 開頭,這應該允許您使用 VSCode 或 chrome 輕松調試,您只需要確保正確配置 launch.json 並匹配地址和端口。
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "localhost",
"port": 9229, // Or 5858
"sourceMaps": true,
"localRoot": "${workspaceRoot}"
}
此外,如果需要,這應該允許您升級到 node > 6.5.0,但需要注意的是,我相信您需要更改 Azure 函數中的運行時才能啟用它。
看起來您在 host.json 附近沒有函數文件夾。 您能否確認您有以下文件夾:C:\\Users\\xxxxxx\\code\\test-repos\\NodeRepo1\\{yourFunctionN ame}? 如果不使用創建它:
func new -l Javascript -t TimerTrigger -name myTimer
之后你應該看到: 你應該在啟動日志中看到類似的內容:
[10/16/2017 11:05:15 PM] Found the following functions:
[10/16/2017 11:05:15 PM] Host.Functions.myTimer
這是一個更清晰的答案。 我也沒有發現微軟的文章很清楚, Alexey Rodionov 的答案讓我走上了正確的道路。
假設您要將端點引用為http://localhost:7071/api/MyFunction
目錄結構應如下所示:
以下兩個文件位於解決方案的根目錄。
我發現 Microsoft 的文章中遺漏了一個事實,即您必須在步驟之間更改目錄。
func init Sample
cd Sample
func new --language JavaScript --template "Http Trigger" --name MyFunction
` 請注意,您在文章中指定“Http 觸發器”的方式也不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.