Back

Project blocked due to cloud functions

  • 0
  • Cloud
stealth
29 Jan, 2025, 06:16

Two of my projects are blocked when using functions

Code :

import { Client, Account ,Databases} from 'node-appwrite';

// This Appwrite function will be executed every time your function is triggered export default async ({ req, res, log, error }) => { if (req.method === 'OPTIONS') { return res.send('', 204, { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Appwrite-Key' }); } // Initialize the Appwrite client const client = new Client() .setEndpoint("https://6799b7db75f3f1251f5f.appwrite.global/v1") .setProject("6798f12500186de1e61d") .setKey(process.env.API_KEY);

// Initialize the Databases service const databases = new Databases(client);

const databaseId = "6798f1b2001d31742ec7"; const collectionId = "6798f1b9001f01d4c0c3";

try { // Fetch all documents from the specified collection const documentList = await databases.listDocuments(databaseId, collectionId);

TypeScript
return res.json({
  success: true,
  documents: documentList.documents,
}, 200, {
  'Access-Control-Allow-Origin': '*',
});

} catch (err) {

TypeScript
// Return the error with appropriate CORS headers
return res.json({
  success: false,
  error: err.message,
}, 500, {
  'Access-Control-Allow-Origin': '*',
});

} };

TL;DR
Problem: Two projects are blocked when using cloud functions in Node.js with Appwrite. Solution: The code provided seems to be properly setting up the Appwrite client and handling CORS headers. Look into potential configuration issues with the Appwrite client or check for any errors in the cloud function execution.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more