0
8
KKKhalid Khan
This code exports an async function that takes in two arguments: req and res for appwrite. The first argument is an object containing the request variables (including the payload), the second is a response object that will be sent back to the client. The function first creates an object containing the payload and secret key, and then creates a random number. The function then sets the APPWRITE_FUNCTION_TRIGGER environment variable to the value of the trigger variable. Finally, the function sends the response object back to the client.
Shortcut: appwrite.createfunction
module.exports = async (req, res) => {
const payload =
req.payload ||
'Add custom data when executing function.';
const secretKey =
req.env.SECRET_KEY ||
'SECRET_KEY environment variable not found. You can set it in Function settings.';
const randomNumber = Math.random();
const trigger = req.env.APPWRITE_FUNCTION_TRIGGER;
res.json({
res.json
});
}