diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 9d91809..6963b99 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -14,6 +14,18 @@ server { root /usr/share/nginx/html; index index.html; + # --- WebSocket-Route --- + # Dieser Block fängt Anfragen an /ws ab und leitet sie mit den + # nötigen Headern für eine WebSocket-Verbindung weiter. + location /ws { + proxy_pass http://bierbaron_backend; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } + + # --- API-Routen (HTTP) --- location ~ ^/(api|auth|me|wallet|slot|admin|health)($|/) { proxy_pass http://bierbaron_backend; proxy_http_version 1.1; @@ -25,14 +37,15 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto; - proxy_set_header Cookie $http_cookie; } + # --- Statisches Frontend (Single Page Application) --- location / { try_files $uri /index.html; } + # Optionale Caching-Regeln für statische Assets location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|webp|woff|woff2|ttf)$ { expires 7d; add_header Cache-Control "public, max-age=604800, immutable"; diff --git a/frontend/src/pages/CrashPage.tsx b/frontend/src/pages/CrashPage.tsx index d8ea3d5..479b9ed 100644 --- a/frontend/src/pages/CrashPage.tsx +++ b/frontend/src/pages/CrashPage.tsx @@ -1,6 +1,6 @@ // frontend/src/pages/CrashPage.tsx import React, { useState, useEffect, useRef } from 'react'; -import { MeResponse } from '../api'; +import { MeResponse, WalletResponse, getWallet } from '../api'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; interface CrashPageProps { @@ -11,11 +11,28 @@ export const CrashPage: React.FC = ({ me }) => { const [phase, setPhase] = useState('connecting'); const [multiplier, setMultiplier] = useState(1.00); const [history, setHistory] = useState<{ time: number, value: number }[]>([]); + const [wallet, setWallet] = useState(null); + const [error, setError] = useState(null); const ws = useRef(null); + // --- HINZUGEFÜGT: Lade das Wallet des Benutzers --- useEffect(() => { - // Die WebSocket-URL muss auf deine Domain zeigen, aber mit wss:// (für https) - const wsUrl = `wss://${window.location.host}`; + async function loadWallet() { + if (me) { + try { + const walletData = await getWallet(); + setWallet(walletData); + } catch (err: any) { + setError("Konnte das Guthaben nicht laden."); + } + } + } + loadWallet(); + }, [me]); + + useEffect(() => { + // --- DER FIX: Verbinde zum /ws Pfad --- + const wsUrl = `wss://${window.location.host}/ws`; ws.current = new WebSocket(wsUrl); ws.current.onopen = () => { @@ -33,7 +50,7 @@ export const CrashPage: React.FC = ({ me }) => { break; case 'newRound': setPhase(data.phase); - setHistory([]); // Graphen zurücksetzen + setHistory([]); setMultiplier(1.00); break; case 'roundStart': @@ -73,26 +90,41 @@ export const CrashPage: React.FC = ({ me }) => { } }; + if (!me) { + return ( +
+

🚀 Bier-Crash

+

Bitte logge dich mit Discord ein, um zu spielen.

+
+ ); + } + return (
-

🚀 Bier-Crash

-
+ {error &&
{error}
} +
{/* Linke Spalte: Steuerung */}
-

Dein Einsatz

- - - +
+

Dein Guthaben

+

+ {wallet ? wallet.balance.toLocaleString('de-DE') : '...'} Bierkästen +

+

Dein Einsatz

+ + + +
{/* Rechte Spalte: Graph und Multiplikator */}
-

+

{multiplier.toFixed(2)}x

{getStatusMessage()}

@@ -100,7 +132,7 @@ export const CrashPage: React.FC = ({ me }) => { - + null} />