Back

[Solved] Blocked by CORS from localhost:5173

  • 0
  • Web
nicosemp
24 May, 2023, 18:51

It must be something really trivial, but I can't find the problem. The URL from which my requests start is http://localhost:5173/. Request URL: https://cloud.appwrite.io/v1/account Status Code: 404 Referrer Policy: strict-origin-when-cross-origin Origin (inside Request Headers): http://localhost:5173

I added a Platform for requests coming from my GH Codespace, and that works fine. However I can't get it to work locally. Searching on this Discord server I saw someone mention the fact that we don't need to create a Platform for localhost. What am I doing wrong?

TL;DR
The user was initially blocked by CORS from localhost:5173 but later realized it was not the issue. They were encountering a 404 error with mismatched project IDs. They verified the project ID and reviewed the code for initializing the Client and Account. The user shared code related to account authentication and asked for help in finding the problem. Requests from localhost were not working, even though requests from another platform were successful. The user was unsure of what they were doing wrong and sought assistance. Solution: Verify that the project ID is correct and check the code for initializing the Client and Account. Additionally, ensure that a Platform is not created for
Binyamin
24 May, 2023, 18:52

Can you share the code?

nicosemp
24 May, 2023, 18:52
TypeScript
try {
  const response = await account.get();
  userID.value = response.$id;
  router.replace('/trips');
} catch (error) {
  if (error instanceof AppwriteException && error.code === 401) {
    // TODO: show error message
  }
  router.replace('/auth');
  console.log(error);
}
nicosemp
24 May, 2023, 18:53

I'm using account from the Appwrite library

Binyamin
24 May, 2023, 18:54

Looks good and localhost should work, How do initializing the Client itself?

nicosemp
24 May, 2023, 18:54
TypeScript
import { Client, Account, Databases, ID } from 'appwrite';

const PROJECT_ID: string = import.meta.env.VITE_APPWRITE_PROJECT_ID;
const DATABASE_ID: string = import.meta.env.VITE_APPWRITE_DATABASE_ID;
const TRIPS_COLLECTION_ID: string = import.meta.env.VITE_APPWRITE_TRIPS_COLLECTION_ID;
const ITEMS_COLLECTION_ID: string = import.meta.env.VITE_APPWRITE_ITEMS_COLLECTION_ID;

const client = new Client();
client.setEndpoint('https://cloud.appwrite.io/v1').setProject(PROJECT_ID);
const account = new Account(client);
const databases = new Databases(client);

export { account, databases, DATABASE_ID, TRIPS_COLLECTION_ID, ITEMS_COLLECTION_ID, ID };
Binyamin
24 May, 2023, 18:56

I see, One of the ways to get 404 is with mismatch project ID, can you verify VITE_APPWRITE_PROJECT_ID once more?

nicosemp
24 May, 2023, 18:59

thank you! I really didn't think of this... I saw CORS and was sure that was the issue 😅

nicosemp
24 May, 2023, 19:00

[Solved] Blocked by CORS from localhost:5173

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