Mosh Ontong
TypeScript
import { initializeAppwriteClient } from "./appwriteConfig.js";
import router from "./apiRoutes.js";
import { isUpdateEvent } from "./util/createTeamUtil.js";
export default async ({ req, res, log, error }: any) => {
const triggered = req.headers["x-appwrite-trigger"];
const path = req.path;
const method = req.method;
const eventType = req.headers["x-appwrite-event"];
log(`Request received by ${path} with method ${method}`);
log(`Triggered type: ${triggered}`);
log(`Event type: ${eventType}`);
try {
if (triggered === "event" && path === "/" && method === "POST") {
if (isUpdateEvent(req, eventType)) {
req.path = "/v1/teams";
}
}
const client = initializeAppwriteClient();
return res.send(
{
message: "Hello from Appwrite Cloud Functions!",
},
200,
{
"content-type": "application/json",
}
);
return await router.handleRequest({ req, res, log, error, client });
} catch (e) {
// Handle initialization errors
error(`Initialization failed: ${e.message}`);
return res.send(
{
message: `Initialization failed: ${e.message}`,
},
500,
{
"content-type": "application/json",
}
);
}
};
Focus on this code:
TypeScript
return res.send(
{
message: "Hello from Appwrite Cloud Functions!",
},
200,
{
"content-type": "application/json",
}
);
as you can see in that code I am sending an json, now the result gives me an object
TL;DR
The user was experiencing an issue where the result of their code was returning an object instead of JSON. They mentioned using JSON.stringify to solve the problem. Mosh Ontong
I solved btw, I used JSON stringify, but its weird in javascript it is fine without using JSON stringify
Recommended threads
- HTTP POST to function returning "No Appw...
Hi everyone, I’m running into an issue with my self-hosted Appwrite instance. I’ve set up my environment variables (APPWRITE_FUNCTION_PROJECT_ID, APPWRITE_FUNC...
- Can't add dart 3.5 runtime
Modified the `.env` to enable dart 3.5 runtime on my self-hosted instance but still can't find the runtime when creating a new function. I manually pulled the i...
- How to verify an user using AppWrite Fun...
I have seen similar questions but none whose solutions serve me. I have a function to verify a user with their secret and their id: https://blahblah.appwrite.gl...