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
- DeploymentStatus enum value `canceled` m...
Hey, Sorry if it has been reported already, I found an issue using the Dart SDK where the `canceled` enum value is missing from `DeploymentStatus`. This causes...
- Synchronous function execution timeout w...
I am calling server functions with xasync = true and I still get this error message. Synchronous function execution timed out. Use asynchronous execution inste...
- Function running for more than 2 hours i...
This is my projectID: 669fe01b003800dd0503 Cloud functionID is 696ea05400147eb8eb3b I hope this doesn't count against my GB-hours?