Back

CORS with Svelte + TS + ViteApp

  • 0
  • Databases
  • Web
ThibaultJP
26 Jul, 2023, 15:16

Hi, I have a CORS issue with the Svelte Template for App-Write

My docker-compose is OK. I access appwrite with http://localhost:8080/console My Svelte frontend is OK http://127.0.0.1:3000/#/login

But when I tried to connect I have this issue :

TypeScript
Access to XMLHttpRequest at 'http://localhost:8080/v1/account/sessions/email' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: Request header field x-sdk-name is not allowed by Access-Control-Allow-Headers in preflight response.
browser-ponyfill.js:518     POST http://localhost:8080/v1/account/sessions/email net::ERR_FAILED

My .env file copied from .env.example file contain :

TypeScript
VITE_APP_ENDPOINT=http://localhost:8080/v1
VITE_APP_PROJECT=64c130a644bddf1a4762
VITE_APP_COLLECTION_ID=64c13113a2d097892fde
VITE_APP_DATABASE_ID=todo

And multiple _APP_..... properties

I don't understand the CORS problem 😢

**AND ** I don't know where find the DATABASE_ID . Isn't on UI And the UI is outdated (old version of appwrite)

The link : https://github.com/appwrite/demo-todo-with-svelte

Thanks ❤️

TL;DR
The user is experiencing a CORS issue with their Svelte template for App-Write. They have Docker setup correctly and can access Appwrite and their Svelte frontend on their local machine. However, when trying to connect, they receive a CORS error. The error message states that the request header field 'x-sdk-name' is not allowed by Access-Control-Allow-Headers in the preflight response. To resolve the issue, the user needs to add the localhost URL to the project overview page in Appwrite. They can access their Svelte app through http://localhost:3000/#/login instead of using the IP address. The user also mentions
Binyamin
26 Jul, 2023, 15:22

The fasts solution would be to access your Svelte through localhost like so http://localhost:3000/#/login

Binyamin
26 Jul, 2023, 15:23

The reason it happened is because Appwrite require you add platform for each Web app accessing your Appwrite. localhost is always allowed. But 127.0.0.1 or any other IP or domain aren't

You can add ``127.0.0.1` if you want or any other in the project overview page

Binyamin
26 Jul, 2023, 15:23

Also, check here for more details https://appwrite.io/docs/getting-started-for-web

ThibaultJP
27 Jul, 2023, 06:20

Thanks for the answer I followed the guide and tried with localhost and 127.0.0.1, there's no difference. And you can't add a port to the platform URL.

I tried with a cloud version of the application and it works fine, but not with the self hosted version with local docker.

ThibaultJP
27 Jul, 2023, 06:21

The 127.0.0.1 comes from a copy-paste of my browser's URL, but I do use http://localhost:3000 to access my svelte front 🤔

Drake
27 Jul, 2023, 21:29

use localhost when accessing appwrite.

Are you using localhost for the endpoint in your app code?

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