mastermind/notes.txt

140 lines
7.7 KiB
Plaintext
Raw Permalink Normal View History

2026-11-21 23:50:50 +03:00
In this directory, you will see a REST API developed by Java Spring boot and a react web application.
this is a game and single player has been already developed. However, multiplayer is missing.
In the same logic, I would like to develope multiplayer version with you.
Requirements:
- There is no db connection so everybody would be create a new game.
- when multiplayer page lists all available games.
- each game has two status (waiting, playing, closed)
- each game has start with two player (not more and not less)
- multiplayer page has also create new game button.
- when a player click to new play, a modal appears and start with the following fields
Game Name: Unique
Number Limit: 3-10 digits
Game Type: auto guesstures, player guesstures, time challenge
- game waits while two players are online
- when one of player leaves the game, the game is over.
auto guesstures: two different guess numbers are randomly created by the game for the players. each turns run together (first guess waits the other). after the turn each youser see his own guess resut and rival's resutl.
both scors will show, when a player find the number
Number selection rule will be the same as single player (each number will be used one time)
player guesstures: before start this game each players set a rival's guesstures number suitable for number selection rule. the rest of the game is the same with auto guesstures type.
time challenge: the game creates a number for the both players. turns go forward independently. players cannot see the rival's guess.
There is a time counter in this game. the game continue until both user find the number. the best score win the game.
Please create a score calculation rule depening on time and turn count.
Please update api service and web application.
2026-11-22 16:11:04 +03:00
Finally please create a summary note in the current directory
I increased the property like that multiplayer.player-timeout-ms=900000.
If it is possible, please update the code according to the following Requirements
- Until play do not click aboard button, game continues.
- if players left the game in a reason, they can return their own game.
- as far as I understand we recognise a player from its token. If they loss their token, game is over after 15 min.
- backend code is available in app directory
2026-11-22 22:08:49 +03:00
Finally please update the summary note in the current directory
---
Projeyi inceledim. Kısaca: Node.js'e geçmenize gerek yok. Sorunların ikisi de nginx ayarından kaynaklanıyor ve mevcut nginx'i proxy olarak kullanmanız doğru yol.
1. Reload'da 403 Forbidden hatası
next.config.mjs içinde output: 'export' var. Build sonucu web/out altında şu dosyalar oluşuyor:
multiplayer.html ← /mastermind/multiplayer sayfası
multiplayer/ ← klasör (içinde index.html yok, sadece play.html var)
single-player.html
Sayfa reload edildiğinde nginx try_files $uri $uri/ =404; kuralını uyguluyor. /mastermind/multiplayer isteğinde $uri/ kısmı multiplayer/ klasörüyle eşleşiyor. Klasörde index.html olmadığı için nginx klasörü listelemeyi reddediyor ve 403 dönüyor. Uygulama içinde link ile gezerken sorun çıkmıyor, çünkü yönlendirmeyi Next tarayıcıda yapıyor.
Çözüm (ikisinden biri yeterli):
nginx tarafında: try_files $uri $uri.html $uri/ =404;, yani .html denemesini klasörden önce yapmak.
Next tarafında: next.config.mjs içine trailingSlash: true eklemek. Bu durumda her sayfa multiplayer/index.html şeklinde üretilir.
2. Güncellemeden sonra tarayıcı cache sorunları
Next'in _next/static/... altındaki dosyalarının adları hash içeriyor, yani her build'de değişiyor. Sorun HTML dosyalarında:
Tarayıcı ya da Cloudflare eski index.html'i cache'ten veriyor. Eski HTML eski chunk'ları istiyor, ama siz klasörü silip yeni out'u kopyaladığınız için o chunk'lar artık yok. Sonuç: bozuk sayfa veya ChunkLoadError.
nginx'te hiç cache header'ı yok, bu yüzden tarayıcı tahmini (heuristic) cache uyguluyor.
Çözüm:
HTML dosyaları için Cache-Control: no-cache, _next/static için max-age=31536000, immutable gönderin (aşağıdaki config'te var).
Cloudflare'de HTML'i cache'leyen bir "Cache Everything" kuralı varsa /mastermind/*.html ve /mastermind/ için bypass ekleyin, ya da her deploy sonrası "Purge Cache" yapın.
Deploy'u klasörü silip kopyalayarak yapmak yerine container image ile yapın (aşağıda). Böylece geçiş tek adımda olur.
3. Node.js mi, nginx mi?
Proje tamamen statik export. next start bu modda çalışmıyor, SSR kullanmıyorsunuz ve Node'un sağlayacağı ek bir şey yok. Statik dosya sunmakta nginx Node'dan daha hızlı ve daha hafif.
Önerim şu yapı:
Cloudflare → Ana nginx (reverse proxy)
├─ /mastermind/ → mastermind-web container (nginx:alpine + out)
└─ /mastermind/api/ → mastermind-api container (Spring, port dışarı kapalı)
web/Dockerfile zaten bu amaçla yazılmış, ancak şu an çalışmıyor: npm run export diye bir script yok (Next 15'te kaldırıldı). Ayrıca basePath=/mastermind olduğu için dosyaların container içinde /usr/share/nginx/html/mastermind altına kopyalanması gerekiyor.
4. Backend dışarı açık mı kalmalı, içeride mi?
İçeride kalmasını öneririm. Şu an web https://api.mmkilic.com/api-mastermind adresine gidiyor ve API 8005 portundan dışarıya açık. Aynı origin üzerinden proxy'lemenin faydaları:
CORS ayarına gerek kalmaz (SecurityConfig içindeki origin listesiyle uğraşmazsınız).
API portu host'a publish edilmez, doğrudan erişilemez.
Tek domain ve tek SSL olur, Cloudflare kuralları da tek yerde toplanır.
Multiplayer polling ile çalışıyor (WebSocket veya SSE yok), bu yüzden proxy tarafında ek bir ayar gerekmiyor. Başka projeler de api.mmkilic.com adresini kullanıyorsa o domain açık kalabilir. Mastermind'ı içeri almak onları etkilemez.
Örnek yapılandırma
Ortak docker network (bir kez çalıştırın; ana nginx container'ını da bu ağa bağlayın):
docker network create proxy-net
docker network connect proxy-net <ana-nginx-container>
web/nginx.conf (web container'ı içinde):
server {
listen 80;
root /usr/share/nginx/html;
location /mastermind/_next/static/ {
add_header Cache-Control "public, max-age=31536000, immutable";
}
location /mastermind/ {
try_files $uri $uri.html $uri/index.html =404;
add_header Cache-Control "no-cache";
}
gzip on;
gzip_types text/plain application/javascript text/css application/json;
}
web/Dockerfile:
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build # .env.production kullanılır
FROM nginx:stable-alpine
COPY --from=builder /app/out /usr/share/nginx/html/mastermind
COPY nginx.conf /etc/nginx/conf.d/default.conf
web/.env.production:
NEXT_PUBLIC_BASE_PATH=/mastermind
NEXT_PUBLIC_API_URL=/mastermind/api
Ana nginx (proxy):
location /mastermind/api/ {
proxy_pass http://c_app_mastermind:8080/api-mastermind/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /mastermind/ {
proxy_pass http://c_mastermind_web:80;
proxy_set_header Host $host;
}
docker-compose.yml dosyalarında: API'den ports: 8005:8080 satırını kaldırın, iki servisi de proxy-net ağına ekleyin (networks: { default: { external: true, name: proxy-net } }).
Hızlı geçici çözüm
Mimariyi şimdilik değiştirmek istemiyorsanız, ana nginx'teki /mastermind bloğuna yukarıdaki try_files ... $uri.html satırını ve iki Cache-Control kuralını eklemeniz bile hem 403 hatasını hem cache sorununun büyük kısmını çözer.
İsterseniz bu değişiklikleri (Dockerfile, nginx.conf, env, compose ve gerekiyorsa SecurityConfig) projeye uygulayabilirim.