feat(frontend): rebuild as SSR with server-authoritative shared state
Rombak total alur data frontend: dari static-export CSR (tiap browser fetch sendiri + akumulasi state voice per-tab) jadi server-side rendering. Frontend (Next.js): - next.config: output export -> standalone; halaman jadi server components - server data layer baru src/lib/api/server.ts (GMW_BACKEND_URL, no window) - dashboard/media/messages/moderation/recordings/voice page -> RSC yang fetch backend di render-time, seed ke client view (SWR fallbackData) - hook-hook utama terima initialData -> first paint data server, revalidate SWR setelahnya, tanpa spinner-blank-load - messages: guild/channel/tab/selected dibaca dari URL di server, page awal di-fetch server-side Shared realtime state (voice) server-authoritative: - backend src/modules/voice/live-speaker.ts: agregat voice_active_user dari gateway jadi snapshot authoritatif (single source of truth semua browser) - GET /api/voice/status kini include activeSpeakers - WS initial states kirim voice_state snapshot saat connect (late join langsung dapat state yang sama, bukan daftar kosong) - useSpeakers seed dari server snapshot + voice_state full-replace + voice_active_user delta upsert Deploy: - flake.nix: frontend package build SSR standalone (server.js wrapper, GMW_FRONTEND_PORT=4017); proxy nginx template proxy / -> Next server, /api + /ws tetap ke backend :4001
This commit is contained in:
@@ -223,7 +223,7 @@ WRAPPER
|
||||
};
|
||||
};
|
||||
|
||||
# ---- Frontend (Next.js static export) ----
|
||||
# ---- Frontend (Next.js SSR standalone) ----
|
||||
frontend = pkgs.stdenv.mkDerivation {
|
||||
pname = "gmw-frontend";
|
||||
version = "1.0.0";
|
||||
@@ -233,29 +233,40 @@ WRAPPER
|
||||
nativeBuildInputs = [ nodejs pnpm pkgs.gnumake pkgs.gcc pkgs.cacert ];
|
||||
|
||||
buildPhase = pnpmInstall + ''
|
||||
echo "=== Building Next.js static export ==="
|
||||
# Build args are provided as env vars
|
||||
echo "=== Building Next.js SSR (standalone) ==="
|
||||
export NEXT_TELEMETRY_DISABLED=1
|
||||
export GMW_BACKEND_URL=http://127.0.0.1:4001
|
||||
npx next build 2>&1
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/share/gmw-frontend
|
||||
cp -r out $out/share/gmw-frontend/out 2>/dev/null || \
|
||||
cp -r dist $out/share/gmw-frontend/dist 2>/dev/null || \
|
||||
cp -r .next $out/share/gmw-frontend/.next 2>/dev/null || true
|
||||
echo "=== Packaging standalone server ==="
|
||||
mkdir -p $out/lib/gmw-frontend/standalone
|
||||
# The standalone server bundles its own minimal node_modules but
|
||||
# needs the build assets + public copied INSIDE its tree.
|
||||
cp -r .next/standalone/. $out/lib/gmw-frontend/standalone/
|
||||
mkdir -p $out/lib/gmw-frontend/standalone/.next
|
||||
cp -r .next/static $out/lib/gmw-frontend/standalone/.next/static
|
||||
cp -r public $out/lib/gmw-frontend/standalone/public 2>/dev/null || true
|
||||
|
||||
# Copy node_modules for standalone mode if it exists
|
||||
cp -r node_modules $out/share/gmw-frontend/ 2>/dev/null || true
|
||||
mkdir -p $out/bin
|
||||
cat > $out/bin/gmw-frontend << WRAPPER
|
||||
#!${pkgs.runtimeShell}
|
||||
cd $out/lib/gmw-frontend/standalone
|
||||
export PORT=''${GMW_FRONTEND_PORT:-4017}
|
||||
export HOSTNAME=127.0.0.1
|
||||
exec ${nodejs}/bin/node server.js
|
||||
WRAPPER
|
||||
chmod +x $out/bin/gmw-frontend
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "GMW Frontend — Next.js static dashboard";
|
||||
description = "GMW Frontend — Next.js SSR dashboard";
|
||||
platforms = pkgs.lib.platforms.linux;
|
||||
};
|
||||
};
|
||||
|
||||
# ---- Proxy (nginx serving frontend) ----
|
||||
# ---- Proxy (nginx: / -> Next SSR, /api + /ws -> backend) ----
|
||||
proxy = pkgs.stdenv.mkDerivation {
|
||||
pname = "gmw-proxy";
|
||||
version = "1.0.0";
|
||||
@@ -270,11 +281,10 @@ WRAPPER
|
||||
mkdir -p $out/bin $out/etc $out/share
|
||||
|
||||
# Substitute placeholders in nginx template
|
||||
sed \
|
||||
-e "s|@NGINX_MIME@|${pkgs.nginx}/conf/mime.types|g" \
|
||||
-e "s|@FRONTEND_ROOT@|${frontend}/share/gmw-frontend/out|g" \
|
||||
${./infra/nix/nginx.conf.template} \
|
||||
> $out/etc/nginx.conf
|
||||
sed -e "s|@NGINX_MIME@|${pkgs.nginx}/conf/mime.types|g" \
|
||||
-e "s|@NEXT_PORT@|4017|g" \
|
||||
${./infra/nix/nginx.conf.template} \
|
||||
> $out/etc/nginx.conf
|
||||
|
||||
cat > $out/bin/gmw-proxy << WRAPPER
|
||||
#!${pkgs.runtimeShell}
|
||||
@@ -284,7 +294,7 @@ WRAPPER
|
||||
'';
|
||||
|
||||
meta = {
|
||||
description = "GMW Proxy — nginx serving frontend";
|
||||
description = "GMW Proxy — nginx -> Next.js + backend";
|
||||
platforms = pkgs.lib.platforms.linux;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user