[英]Debugging a Node.js Azure function
Hi, I am trying to debug and develop locally a simple JavaScript timerTrigger function azure application but I am having trouble.嗨,我正在尝试在本地调试和开发一个简单的 JavaScript timerTrigger 函数 azure 应用程序,但我遇到了问题。 I am trying to follow along this tutorial: https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
我正在尝试按照本教程进行操作: https : //docs.microsoft.com/en-us/azure/azure-functions/functions-run-local
Please provide the following:请提供以下信息:
I have the application handled via a Git repo so it's on my local machine as well.我通过 Git 存储库处理了该应用程序,因此它也在我的本地机器上。
Provide the steps required to reproduce the problem:提供重现问题所需的步骤:
Go to root level of function app and run (via powershell): func host start --debug vscode
转到函数应用程序的根级别并运行(通过 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] }
Visit in browser http://localhost:7071/admin/functions/noderepo
在浏览器中访问
http://localhost:7071/admin/functions/noderepo
Upon vising my timer trigger, I get:在查看我的计时器触发器后,我得到:
<Error> <Message> The requested resource does not support http method 'GET'. </Message> </Error>
I tried substituting noderepo
with timerTrigger
and myTrigger
in the URL and still same thing.我尝试在 URL 中用
timerTrigger
和myTrigger
替换noderepo
, timerTrigger
仍然是一样的。 How do I debug this?我该如何调试?
Execute the JavaScript function method and break on the VS Code执行 JavaScript 函数方法并在 VS Code 上中断
My index.js
is this:我的
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(); };
Very simple....很简单....
Have you tried running the new version of the Azure tools cli?您是否尝试过运行新版本的 Azure 工具 cli?
npm install azure-functions-core-tools@core
The new version of the cli is build on .NET core and it is x-platform.新版本的 cli 是建立在 .NET 核心之上的,它是 x 平台的。 The architecture doesn't rely on Edge.js anymore instead it offloads processing to a node worker.
该架构不再依赖 Edge.js,而是将处理工作卸载到节点工作器。 The cli worker always starts with --inspect which should allow you to debug easily with VSCode or chrome, you just need to make sure your launch.json is properly configured and matches the address and port.
cli 工作程序始终以 --inspect 开头,这应该允许您使用 VSCode 或 chrome 轻松调试,您只需要确保正确配置 launch.json 并匹配地址和端口。
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "localhost",
"port": 9229, // Or 5858
"sourceMaps": true,
"localRoot": "${workspaceRoot}"
}
Also this should allow you to upgrade to node > 6.5.0 if you need, only caveat I believe you'll need to change the runtime in your Azure function to enable it.此外,如果需要,这应该允许您升级到 node > 6.5.0,但需要注意的是,我相信您需要更改 Azure 函数中的运行时才能启用它。
It looks like you do not have function folder near host.json.看起来您在 host.json 附近没有函数文件夹。 Can you please verify you have following folder: C:\\Users\\xxxxxx\\code\\test-repos\\NodeRepo1\\{yourFunctionName}?
您能否确认您有以下文件夹:C:\\Users\\xxxxxx\\code\\test-repos\\NodeRepo1\\{yourFunctionN ame}? If not create it using:
如果不使用创建它:
func new -l Javascript -t TimerTrigger -name myTimer
After that you should see: You should see in startup logs something like:之后你应该看到: 你应该在启动日志中看到类似的内容:
[10/16/2017 11:05:15 PM] Found the following functions:
[10/16/2017 11:05:15 PM] Host.Functions.myTimer
Here is the answer a little more clearly laid out.这是一个更清晰的答案。 I did not find Microsoft's Article very clear either and it was Alexey Rodionov's answer set set me on the correct route.
我也没有发现微软的文章很清楚, Alexey Rodionov 的答案让我走上了正确的道路。
Assuming that you want to reference the endpoint as http://localhost:7071/api/MyFunction假设您要将端点引用为http://localhost:7071/api/MyFunction
The directory structure should look like this:目录结构应如下所示:
The following two files are at the root of your solution.以下两个文件位于解决方案的根目录。
What I found missing from Microsoft's article was the fact that you had to change directory between the steps.我发现 Microsoft 的文章中遗漏了一个事实,即您必须在步骤之间更改目录。
func init Sample
cd Sample
func new --language JavaScript --template "Http Trigger" --name MyFunction
` Note that the way you specify "Http Trigger" is also not correct in the article. ` 请注意,您在文章中指定“Http 触发器”的方式也不正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.