Leitet /v1 an ticket.webklar.com weiter und dokumentiert .env.local, damit Session-Cookies auf localhost wie auf dem Server funktionieren. Co-authored-by: Cursor <cursoragent@cursor.com>
2.3 KiB
2.3 KiB
Lokale Entwicklung (Appwrite)
Warum funktioniert es auf dem Server, aber nicht mit npm run dev?
Server (ticket.webklar.com) |
Lokal (localhost:5173) |
|
|---|---|---|
| App-URL | https://ticket.webklar.com |
http://localhost:5173 |
| API-URL | https://ticket.webklar.com/v1 (nginx-Proxy) |
oft https://ticket.webklar.com/v1 direkt |
| Gleiche Origin? | Ja | Nein (Cross-Origin) |
| Session-Cookie | domain=.ticket.webklar.com |
Browser speichert Cookie nicht für localhost |
Auf dem Server leitet nginx /v1/ an Appwrite weiter und schreibt Cookies auf ticket.webklar.com um. Die React-App und die API sind dieselbe Site — Login funktioniert.
Lokal ruft der Browser die API auf einer anderen Domain auf. Appwrite setzt Cookies für .ticket.webklar.com. Die werden bei Requests von localhost:5173 nicht mitgeschickt ? guests missing scopes, Login scheint tot.
CORS für http://localhost:5173 ist auf dem Server erlaubt — das reicht allein nicht für HttpOnly-Session-Cookies.
Lösung: Vite-Proxy + .env.local
-
Datei anlegen (nicht in Git):
cp .env.example .env.local -
In
.env.localmuss stehen:VITE_APPWRITE_ENDPOINT=http://localhost:5173/v1 VITE_APPWRITE_PROJECT_ID=6a1058610003c5a13a05 VITE_APPWRITE_DATABASE_ID=woms-database VITE_APPWRITE_BUCKET_ID=woms-attachments -
Dev-Server starten:
npm install npm run dev
vite.config.js leitet /v1 an https://ticket.webklar.com weiter und schreibt Cookie-Domains auf localhost um — Verhalten wie nginx auf dem Server.
Checkliste bei Problemen
.env.localexistiert (.envallein reicht; Vite lädt.env.localmit höherer Priorität)- Endpoint ist
http://localhost:5173/v1, nichthttps://appwrite.webklar.com/v1(altes Projekt) - Nach Login: DevTools ? Application ? Cookies ?
localhost?a_session_6a1058610003c5a13a05 - Appwrite Console ? Projekt Ticket-System ? Platforms ?
localhosteingetragen
Git / Deploy
.envund.env.localsind in.gitignore— jeder Entwickler braucht eigene.env.local- Server-Build nutzt Container-Env (
VITE_APPWRITE_ENDPOINT=https://ticket.webklar.com/v1) - Push nach Gitea deployt nur den Frontend-Code, nicht deine lokale
.env.local