简体   繁体   English

Azure Functions Node.js自定义入口点

[英]Azure Functions Node.js custom entrypoint

I'm writing a cloud function and trying to add support for several providers. 我正在编写云功能并尝试添加对多个提供商的支持。 Currently for Google Cloud and AWS Lambda this has been simple enough, as both allow me to specify a named export of a given file (index.js in root folder) as the entrypoint for function execution. 目前对于Google Cloud和AWS Lambda来说,这已经足够简单,因为它们都允许我指定给定文件的命名导出(根文件夹中的index.js)作为函数执行的入口点。

All was good I thought, but now I want to add Azure support, but it seems to insist on having a folder with the function name with its own index.js which is the entrypoint for execution. 一切都很好我想,但现在我想添加Azure支持,但它似乎坚持拥有一个带有自己的index.js的函数名的文件夹,这是执行的入口点。 Unfortunately this breaks the architecture I have in place (have made it generic to allow one entrypoint for multiple providers with some runtime detection of execution environment to return correct function type for that provider). 不幸的是,这打破了我所拥有的架构(使其具有通用性,允许多个提供程序的一个入口点以及执行环境的某些运行时检测为该提供程序返回正确的函数类型)。

Is it possible at all with Azure to do something similar to GCF or Lambda and simply say 'I want a HTTPS triggered function that starts at this export of this file', and it trusts you to do the rest? Azure是否可以执行类似于GCF或Lambda的操作,并简单地说'我想要从此文件的导出开始的HTTPS触发函数',并且它相信你做其余的事情?

Azure documentation has not been much help, neither have I been able to find much of use on Google. Azure文档没有太大帮助,我也没能在Google上找到很多用处。

You do need a folder for each function to map the entry point to the correct script file. 每个函数都需要一个文件夹,以将入口点映射到正确的脚本文件。 But this folder only needs the function.json file to configure this. 但是这个文件夹只需要function.json文件来配置它。 Your code can be in a different location, for example all functions bundled inside one file - that's what Azure Functions Pack is doing. 您的代码可以位于不同的位置,例如捆绑在一个文件中的所有函数 - 这就是Azure Functions Pack正在执行的操作。

Inside the function.json you can set the script file like this: 在function.json中你可以像这样设置脚本文件:

{
 "disabled": false,
 "bindings": [
  {
   "authLevel": "anonymous",
   "type": "httpTrigger",
   "direction": "in",
   "name": "req",
   "methods": [
    "get"
   ]
  },
  {
   "type": "http",
   "direction": "out",
   "name": "res"
  }
 ],
 "scriptFile": "../.funcpack/index.js",
 "entryPoint": "HttpTrigger1"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM