This repository has been archived on 2026-05-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tippspiel/backend/SETUP.md
T
2026-04-03 21:41:19 +02:00

115 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# WM 2026 Tippspiel Backend Setup
## Voraussetzungen
- Node.js 20+
- npm oder pnpm
- Supabase Account (kostenlos)
- football-data.org API Key (kostenlos)
- Railway oder Render Account (Hosting)
---
## 1. Supabase einrichten
1. Projekt anlegen unter https://supabase.com
2. SQL Editor öffnen → `src/db/schema.sql` vollständig ausführen
3. Unter **Settings → Database → Connection string** die `DATABASE_URL` kopieren
4. Unter **Settings → API → service_role key** den Service Role Key kopieren
---
## 2. Staffbase Plugin Public Key
1. In Staffbase Studio: **Plugins → Neues Plugin anlegen**
2. Plugin-Typ: **External Web App (iFrame)**
3. Den angezeigten **Public Key (RSA)** kopieren
4. In `.env` als `STAFFBASE_PUBLIC_KEY` eintragen (mehrzeilig mit `\n` oder in Anführungszeichen)
---
## 3. football-data.org API Key
1. Registrieren unter https://www.football-data.org/client/register
2. API Key per E-Mail erhalten → in `.env` als `FOOTBALL_API_KEY` eintragen
---
## 4. Lokale Entwicklung
```bash
cd backend
npm install
cp .env.example .env
# .env mit echten Werten befüllen
npm run dev
# → Server läuft auf http://localhost:3001
# → Health Check: http://localhost:3001/health
```
---
## 5. Deployment auf Railway
```bash
# Railway CLI installieren
npm install -g @railway/cli
# Login
railway login
# Projekt erstellen und deployen
railway init
railway up
# Environment Variables setzen (einmalig)
railway variables set DATABASE_URL="..." \
STAFFBASE_PUBLIC_KEY="..." \
FOOTBALL_API_KEY="..." \
NODE_ENV=production \
CORS_ORIGIN="https://app.staffbase.com"
```
---
## 6. Ersten Sync durchführen
Nach dem Deployment:
```bash
# Spiele von football-data.org laden (als Editor-User via Staffbase)
POST /api/admin/sync
# Oder direkt via curl (mit gültigem JWT):
curl -X POST https://your-app.railway.app/api/admin/sync \
-H "Authorization: Bearer <staffbase_jwt>"
```
---
## API Übersicht
| Method | Endpoint | Beschreibung |
|--------|----------|--------------|
| GET | `/health` | Health Check |
| GET | `/api/matches` | Alle Spiele (mit eigenem Tipp) |
| GET | `/api/matches/:id` | Einzelnes Spiel |
| POST | `/api/tips` | Tipp abgeben / aktualisieren |
| GET | `/api/tips` | Eigene Tipps |
| GET | `/api/leaderboard` | Rangliste (Top 50) |
| GET | `/api/leaderboard/me` | Eigene Statistiken |
| POST | `/api/admin/sync` | Spiele synchronisieren (Editor) |
| POST | `/api/admin/evaluate` | Tipps auswerten (Editor) |
| GET | `/api/admin/stats` | Admin-Statistiken (Editor) |
---
## Punkte-System
| Ergebnis | Punkte |
|----------|--------|
| Exaktes Ergebnis | **3** |
| Richtige Tendenz (S/U/N) | **1** |
| Falsche Tendenz | **0** |