Docs 菜单

函数配置文件

注意

本页介绍一种旧版配置文件格式。只有在使用已弃用的realm-cli时,才应使用此信息。

使用 App Services CLI 拉取或从用户界面导出的任何配置文件都使用最新配置版本。 有关当前配置文件格式的详细信息,请参阅应用程序配置。

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

The name of the function. The name must match the file name of a source code file and be unique among all functions in your application.

private
Boolean

如果true ,则只能从其他函数或在%function规则表达式中调用此函数。 您不能直接从客户端应用程序或使用 SDK 调用私有函数。

can_evaluate
JSON Expression (default: true)

如果允许执行函数,则JSON 表达式的计算结果为true 。 App Services 会为每个传入请求计算此表达式。

disable_arg_logs
Boolean

如果true ,则 App Services 将省略函数执行日志条目中为函数提供的参数。

run_as_system
Boolean

If true, this function runs as the system user. 这会覆盖为run_as_user_idrun_as_user_id_script_source定义的任何值。

run_as_user_id
String

函数执行时始终使用的App Services 用户的唯一 ID。 不能与run_as_user_id_script_source一起使用。

run_as_user_id_script_source
String

一个字符串化函数,在调用该函数时运行,并返回该函数执行时使用的App Services 用户的唯一 ID。 不能与run_as_user_id一起使用。

您可以在/functions目录内的.js文件中定义函数的源代码,该文件使用函数名称作为文件名。 每个文件必须导出在请求调用该函数时运行的主函数。

重要

所有函数源代码文件必须位于/functions目录中。

/functions/<function name="">.js</function>
exports = function addOne(input) {
if(typeof input !== "number") {
throw new Error("You must call addOne() with a number");
}
return input + 1;
};