Switch Next.js to standalone output for reliable SSR deployment
This commit is contained in:
1 parent
e223705fa2
commit
4171261bea
2 files changed
+14
-20
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
output: "standalone",
|
||||||
/* config options here */
|
/* config options here */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+13
-20
@@ -112,32 +112,25 @@ echo ">>> Building Next.js SSR App inside monorepo temp dir..."
|
|||||||
cd $TEMP_DIR/apps/ssr
|
cd $TEMP_DIR/apps/ssr
|
||||||
$BUN run build # build จาก monorepo (workspace:* resolve ได้)
|
$BUN run build # build จาก monorepo (workspace:* resolve ได้)
|
||||||
|
|
||||||
echo ">>> Syncing built SSR App to $TARGET_SSR..."
|
# E. Prepare Next.js SSR
|
||||||
mkdir -p $TARGET_SSR
|
echo ">>> Preparing Next.js SSR App..."
|
||||||
|
|
||||||
# Sync ทั้ง source + .next/ ไปยัง TARGET_SSR
|
|
||||||
rsync -av --delete \
|
rsync -av --delete \
|
||||||
--exclude='.env' \
|
$TEMP_DIR/apps/ssr/.next/standalone/ $TARGET_SSR/
|
||||||
--exclude='.env.local' \
|
rsync -av \
|
||||||
--exclude='node_modules/' \
|
$TEMP_DIR/apps/ssr/public/ $TARGET_SSR/apps/ssr/public/
|
||||||
$TEMP_DIR/apps/ssr/ $TARGET_SSR/
|
rsync -av \
|
||||||
|
$TEMP_DIR/apps/ssr/.next/static/ $TARGET_SSR/apps/ssr/.next/static/
|
||||||
|
|
||||||
# Sync packages ไปด้วย
|
# F. Fix Permissions
|
||||||
mkdir -p $TARGET_SSR/packages
|
echo ">>> Fixing Permissions..."
|
||||||
rsync -av $TEMP_DIR/packages/ $TARGET_SSR/packages/
|
chown -R ti:ti $TARGET_BACKEND $TARGET_SSR
|
||||||
|
|
||||||
# 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/
|
|
||||||
|
|
||||||
# H. PM2 Management - SSR Next.js
|
# H. PM2 Management - SSR Next.js
|
||||||
cd $TARGET_SSR
|
cd $TARGET_SSR
|
||||||
echo ">>> Managing PM2 Process: $PM2_NAME_SSR..."
|
echo ">>> Managing PM2 Process: $PM2_NAME_SSR..."
|
||||||
NEXT_VER=$(grep '"next":' package.json | sed -E 's/.*"next": "[\^~]?([0-9\.]+)".*/\1/')
|
$PM2 delete $PM2_NAME_SSR 2>/dev/null || true
|
||||||
$PM2 restart $PM2_NAME_SSR 2>/dev/null || \
|
PORT=$SSR_PORT $PM2 start $BUN --name $PM2_NAME_SSR \
|
||||||
$PM2 start $BUN --name $PM2_NAME_SSR \
|
-- apps/ssr/server.js
|
||||||
-- x next@$NEXT_VER start -p $SSR_PORT
|
|
||||||
echo "✅ PM2 process '$PM2_NAME_SSR' is running on port $SSR_PORT."
|
echo "✅ PM2 process '$PM2_NAME_SSR' is running on port $SSR_PORT."
|
||||||
|
|
||||||
# I. Cleanup
|
# I. Cleanup
|
||||||
|
|||||||
Reference in new issue
Block a user