Taking this example on how to build a Function in JS from the docs:
export default async ({ req, res, log }) => {
switch (req.query.type) {
case 'empty':
return res.empty();
case 'json':
return res.json({"type": "This is a JSON response"});
case 'redirect':
return res.redirect("https://appwrite.io", 301);
case 'html':
return res.send(
"<h1>This is an HTML response</h1>", 200, {
"content-type": "text/html"
});
default:
return res.send("This is a text response");
}
}
I wonder if there's some documentation on the typing of req, res and log? Or even better a dependency I can pull in for it... I actually develop in TypeScript and use Bun for execution, and not having any typing is hard. E.g. can I pass a status code to res.json()? Which parameter would it be? Will it always be the second one? Can I always send headers on the third parameter? What's the fourth parameter?
I found a comment in one of the projects, which hints to types, but it's a comment (not code or types) and it's not complete: https://github.com/appwrite/functions-starter/blob/main/node-18.0/src/index.js
Recommended threads
- HUGE OUTRAGE IN APPWRITE, I CANNOT ACCES...
I have 2k users trying to access, sending me messages. What am I supposed to do? Please solve this asap.
- All my apps are not opening now
All my apps are not opening now 200+ apps are not opening plz fast
- Dotnet functions on cloud
I'm trying to deploy my .Net8 functions to my project on cloud.appwrite through the CLI. I'm getting this error.