首页 > 解决方案 > 我如何观察我的天蓝色功能的变化?

问题描述

我正在使用用 NODE JS 编写的天蓝色函数。我正在启动本地服务器

func host start

一切正常。但问题是当我在我的天蓝色函数中更改某些内容时 - 例如当我添加一个简单的控制台日志时的 index.js 文件


module.exports = async function (context, req) {
        console.log('request came');
        context.res = {
            body: { success: true, message: null, response: context.bindings.inputDocument }
        };
};

服务器未重新启动,我需要停止服务器再次运行 func host start 以查看不好的更改。在nodejs中,我们有nodemon,在天蓝色的函数中是否有一些东西,我可以在不停止并在每次更改时启动服务器的情况下观察更改?

我试过的

我尝试在我的 host.json 文件中添加

  "watchDirectories": [ "*" ] 

但没有成功。

我也试过

scripts编辑package.json 文件中的 start 属性

"scripts": {
    "start": "start npm run watch & npm run start:host",
    "test": "echo \"No tests yet...\""
  },

反而

"scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },

但仍然没有成功。

我正在使用天蓝色函数 v2。

标签: node.jsazureazure-functionsazure-function-app

解决方案


您可以启动两个进程(基于@azure/functions 1.2.3):

  • 过程1:(tsc -wnpm run watch
  • 过程2:(func startnpm start

然后,Typescript 编译器将在监视模式下工作,自动编译更改,并且 azure func 工具还将在更改时重新加载它的函数。


推荐阅读