在 Appwrite 控制台中,我正在添加一个测试环境变量以传递给函数......
在我的函数代码(NodeJs)index.js 中,我正在注销上述变量的值......
我保存代码并使用 Appwrite CLI (createTag) 推送/发布代码。
然后在 Appwrite 控制台中,我激活新功能,然后执行它,我在日志中看到了这个......
显然我遗漏了一些东西,但我正在搜索 Appwrite 文档但我没有看到它。
我做错了什么?
感谢您的帮助 :-)
好吧,就像这篇文章一样,这是 Appwrite Web UI 代码中的一个错误。您现在可以通过两种方式执行此操作。您可以在代码中设置环境变量,也可以使用 Appwrite CLI。我最终将 CLI 推荐放在了我的 NodeJs package.json 脚本中,以便快速轻松访问。
这两种方法都对我有用...
appwrite functions create --functionId=regions_get_all --name=regions_get_all --execute=[] --runtime=node-16.0 --vars={ 'LT_API_ENDPOINT': 'https://appwrite.league-tracker.com/v1', 'LT_PROJECT_ID': '61eb...7e4ff', 'LT_FUNCTIONS_SECRET': '3b4b478e5a5576c1...ef84ba44e5fc2261cb8a8b3bfee' }
const sdk = require('node-appwrite');
const endpoint = 'https://appwrite.league-tracker.com/v1';
const projectId = '61eb3...7e4ff';
const funcionsSecret = '3b4b478e5a557ab8a...c121ff21977a';
const functionId = process.argv[2];
const name = process.argv[2];
const execute = [];
const runtime = 'node-16.0';
const env_vars = {
"LT_API_ENDPOINT": endpoint,
"LT_PROJECT_ID": projectId,
"LT_FUNCTIONS_SECRET": funcionsSecret
};
// Init SDK
const client = new sdk.Client();
const functions = new sdk.Functions(client);
client
.setEndpoint(endpoint) // Your API Endpoint
.setProject(projectId) // Your project ID
.setKey('33facd6c0d792e...359362efbc35d06bfaa'); // Your secret API key
functions.get(functionId)
.then(
func => {
// Does this function already exist?
if ((typeof (func) == 'object' && func['$id'] == functionId)) {
throw `Function '${functionId}' already exists. Cannot 'create'.\n\n`;
}
// Create the function
functions.create(functionId, name, execute, runtime, env_vars)
.then(
response => console.log(response),
error => console.error(`>>> ERROR! ${error}`)
);
}).catch(
error => console.error(`>>> ERROR! ${error}`)
);