函数配置文件
Atlas Device Sync、数据 API 和 HTTPS Endpoints 已被弃用。请参阅弃用页面以了解详细信息。
app/ └── functions/ ├── config.json └── <function>.js
函数清单
应用中的每个函数在函数清单文件中都有相应的元数据条目: /functions/config.json
。
提示
如果尚未定义配置,Atlas App Services 会在导入时自动将功能添加到清单中。 如果您同意默认设置,则可以跳过定义函数的配置,让 App Services 为您完成此操作。 清单将包含您下次导出或拉取应用程序时生成的配置。
functions/config.json
[ { "name": "<Function Name>", "private": <Boolean>, "can_evaluate": { <JSON Expression> }, "disable_arg_logs": <Boolean>, "run_as_system": <Boolean>, "run_as_user_id": "<App Services User ID>", "run_as_user_id_script_source": "<Function Source Code>" }, ... ]
字段 | 说明 |
---|---|
name string | |
private boolean | 如果 |
can_evaluate object | 如果允许执行函数,则JSON 表达式的计算结果为 |
disable_arg_logs boolean | 如果 |
run_as_system boolean | If |
run_as_user_id string | 函数执行时始终使用的App Services 用户的唯一 ID。 不能与 |
run_as_user_id_script_source string | 一个字符串化函数,在调用该函数时运行,并返回该函数执行时使用的App Services 用户的唯一 ID。 不能与 |
函数源代码
您可以在/functions
目录内的.js
文件中定义函数的源代码,该文件使用函数名称作为文件名。 每个文件必须导出在请求调用该函数时运行的主函数。
重要
所有函数源代码文件必须位于/functions
目录中。
/functions/<function name>.js
exports = function addOne(input) { if(typeof input !== "number") { throw new Error("You must call addOne() with a number"); } return input + 1; };