简体   繁体   中英

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.

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. 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 documentation has not been much help, neither have I been able to find much of use on 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. Your code can be in a different location, for example all functions bundled inside one file - that's what Azure Functions Pack is doing.

Inside the function.json you can set the script file like this:

{
 "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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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