#Can multiple functions exist in one Appwrite cloud function?
11 messages · Page 1 of 1 (latest)
Uhh no. One file will only have 1 default export. But you can do different things based on the event or path
Thanks, Steven. However, do you mean I handle different scenarios in a single function?
Yes just like how an express server has multiple endpoints
Oh ok…thanks
@shy drift please, how do I trigger my function using the http trigger in my application? do i call an endpoint or something?
Thanks
and I guess, calling a function with the SDK means the event trigger is http, right?
can I do something like this in my function:
module.exports.checkPermission = async (userId, resource, action) => {
const response = await fetch(
"https://cloud.appwrite.io/v1/functions/{FUNCTION_ID}/executions",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Appwrite-Project": "YOUR_PROJECT_ID",
"X-Appwrite-Key": "YOUR_API_KEY", // Consider using environment variables
},
body: JSON.stringify({ userId, resource, action }),
}
);
const data = await response.json();
return data.allowed; // true or false
};
You could, but I don't recommend it. Why make the extra network request?