Rank 1: Thread
Hey Appwriters :),
I am new to WebDev, majorily worked in Mobile Industry. So, I have zero knowledge of CORS Errors. I made public cloud function in appwrite using python, wanted to use that in React Project, but for some reasons I am constantly facing CORS error, whereas i can use the function in curl, browser and postman.
This is my source code of appwrite function,
from appwrite.client import Clientimport os
from .notion_api import get_top_news
NOTION_API_KEY = os.environ["NOTION_API_KEY"]
def main(context): return context.res.json( { "notion_top_news": get_top_news(NOTION_API_KEY), } )Whereas I am calling it like this,
export async function fetchTopNews(): Promise<{ notion_top_news: { document_id: string; headline: string; image_url: string; summary: string } }> { const url = 'https://<function-id>.appwrite.global/';
try { const response = await fetch(url);
if (!response.ok) { throw new Error(`Request failed with status: ${response.status}`); }
const data = await response.json();
if (!data.notion_top_news || typeof data.notion_top_news !== 'object') { throw new Error('Invalid JSON format in response'); }
return data as { notion_top_news: { document_id: string; headline: string; image_url: string; summary: string; }; }; } catch (error) { throw new Error(`Failed to fetch data: ${error}`); }}