From 4171261bea784c68be44b762e57f94fa297f4f42 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 3 Jun 2026 09:09:02 +0700 Subject: [PATCH] Switch Next.js to standalone output for reliable SSR deployment --- apps/ssr/next.config.ts | 1 + serverinfo/post-receive | 33 +++++++++++++-------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/apps/ssr/next.config.ts b/apps/ssr/next.config.ts index e9ffa30..ad52782 100644 --- a/apps/ssr/next.config.ts +++ b/apps/ssr/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + output: "standalone", /* config options here */ }; diff --git a/serverinfo/post-receive b/serverinfo/post-receive index 3c583aa..309d374 100644 --- a/serverinfo/post-receive +++ b/serverinfo/post-receive @@ -112,32 +112,25 @@ echo ">>> Building Next.js SSR App inside monorepo temp dir..." cd $TEMP_DIR/apps/ssr $BUN run build # build จาก monorepo (workspace:* resolve ได้) -echo ">>> Syncing built SSR App to $TARGET_SSR..." -mkdir -p $TARGET_SSR - -# Sync ทั้ง source + .next/ ไปยัง TARGET_SSR +# E. Prepare Next.js SSR +echo ">>> Preparing Next.js SSR App..." rsync -av --delete \ - --exclude='.env' \ - --exclude='.env.local' \ - --exclude='node_modules/' \ - $TEMP_DIR/apps/ssr/ $TARGET_SSR/ + $TEMP_DIR/apps/ssr/.next/standalone/ $TARGET_SSR/ +rsync -av \ + $TEMP_DIR/apps/ssr/public/ $TARGET_SSR/apps/ssr/public/ +rsync -av \ + $TEMP_DIR/apps/ssr/.next/static/ $TARGET_SSR/apps/ssr/.next/static/ -# Sync packages ไปด้วย -mkdir -p $TARGET_SSR/packages -rsync -av $TEMP_DIR/packages/ $TARGET_SSR/packages/ - -# Sync root node_modules ไปยัง TARGET_SSR -# (bun workspace ติดตั้ง next ไว้ที่ root node_modules ไม่ใช่ apps/ssr/node_modules) -echo ">>> Syncing root node_modules to $TARGET_SSR..." -rsync -a --delete $TEMP_DIR/node_modules/ $TARGET_SSR/node_modules/ +# F. Fix Permissions +echo ">>> Fixing Permissions..." +chown -R ti:ti $TARGET_BACKEND $TARGET_SSR # H. PM2 Management - SSR Next.js cd $TARGET_SSR echo ">>> Managing PM2 Process: $PM2_NAME_SSR..." -NEXT_VER=$(grep '"next":' package.json | sed -E 's/.*"next": "[\^~]?([0-9\.]+)".*/\1/') -$PM2 restart $PM2_NAME_SSR 2>/dev/null || \ -$PM2 start $BUN --name $PM2_NAME_SSR \ - -- x next@$NEXT_VER start -p $SSR_PORT +$PM2 delete $PM2_NAME_SSR 2>/dev/null || true +PORT=$SSR_PORT $PM2 start $BUN --name $PM2_NAME_SSR \ + -- apps/ssr/server.js echo "✅ PM2 process '$PM2_NAME_SSR' is running on port $SSR_PORT." # I. Cleanup