fix(ops): switch pm2 to standalone server + fix wholesale_settings query
Deploy to route.crispygoat.com / deploy (push) Successful in 4m14s
Deploy to route.crispygoat.com / deploy (push) Successful in 4m14s
Three problems were silently breaking the prod Tuxedo redesign and
the offline DB error swallowed all visibility into them:
1. `next start` against `output: "standalone"` is unsupported. Next.js
prints "next start does not work with output: standalone" and
silently disables the image optimizer — every `/_next/image?url=...`
returned "url parameter is not allowed". pm2 was previously
started as `pm2 start npm -- start -- -p 3100`. Switched to
`node /home/tyler/route-commerce/scripts/start-standalone.cjs`.
2. The standalone server reads `.next/static/` relative to itself, so
deploy must `cp -r .next/static .next/standalone/.next/static` on
every sync. Without this, every `_next/static/chunks/*.js` returns
404 and the page hydration dies. Added to the deploy workflow.
3. bash's `set -a; . ./.env` truncates DATABASE_URL at the `&` in
`&channel_binding=require`, so the standalone server boots with
empty DB env. `getBrandSettingsPublic` then caught the empty-pool
error and returned `{success:false, error:'Failed to fetch brand settings'}`,
so `state.heroImageUrl` stayed null and the hero poster never
rendered. The new `scripts/start-standalone.cjs` parses .env in
Node (which handles `&` correctly) and exec's the server with the
loaded env.
4. `getBrandSettingsPublic` queried `ws.wholesale_enabled`, which
no longer exists in `wholesale_settings`. The schema migration
renamed it to `online_payment_enabled`. Switched the column
reference and added a console.error log so future drift surfaces
instead of being swallowed by the empty catch.
Plus `next.config.ts` had `hostname: "s3.crispygoat.com"` added
under `images.remotePatterns` so the optimizer accepts MinIO URLs.
This commit is contained in:
@@ -204,9 +204,29 @@ jobs:
|
||||
|
||||
# Install deps and restart on server
|
||||
echo "Installing deps and restarting PM2..."
|
||||
# IMPORTANT: --update-env so PM2 re-reads .env. Without it PM2 keeps
|
||||
# the original env vars cached at first start and silently ignores
|
||||
# newly added ones (like SMARTSHEET_*).
|
||||
ssh -o ConnectTimeout=60 -o StrictHostKeyChecking=no tyler@route.crispygoat.com "cd $APP_DIR && npm install --omit=dev 2>&1 | tail -5 && pm2 restart route-commerce --update-env || pm2 start npm --name route-commerce -- start -- -p 3100 && pm2 save && sleep 4 && curl -f -s http://localhost:3100/api/health/db-schema || { echo 'Health check failed after start - schema not applied (see plan)'; exit 1; }"
|
||||
# IMPORTANT: With `output: "standalone"` in next.config.ts we MUST
|
||||
# run `node .next/standalone/server.js` (not `next start`) — `next start`
|
||||
# against a standalone build is unsupported and silently disables the
|
||||
# image optimizer (every `/_next/image?url=...` returns
|
||||
# `"url" parameter is not allowed`). See commit 129c9d2.
|
||||
#
|
||||
# We also need to (1) ship the standalone loader script
|
||||
# `scripts/start-standalone.cjs`, (2) copy `.next/static/` into
|
||||
# `.next/standalone/.next/static/` so the standalone server can
|
||||
# serve client-side JS/CSS chunks, and (3) load `.env` via a
|
||||
# Node loader — bash's `set -a; . ./.env` truncates DATABASE_URL
|
||||
# at the `&` in `&channel_binding=require`.
|
||||
scp -o ConnectTimeout=15 -o StrictHostKeyChecking=no scripts/start-standalone.cjs tyler@route.crispygoat.com:$APP_DIR/scripts/start-standalone.cjs 2>/dev/null || true
|
||||
ssh -o ConnectTimeout=60 -o StrictHostKeyChecking=no tyler@route.crispygoat.com "set -e; cd $APP_DIR && npm install --omit=dev 2>&1 | tail -5 && \
|
||||
# Standalone server reads .next/static/ relative to itself.
|
||||
mkdir -p .next/standalone/.next && \
|
||||
rm -rf .next/standalone/.next/static && \
|
||||
cp -r .next/static .next/standalone/.next/static && \
|
||||
# Start with the wrapper that loads .env and exec's the server.
|
||||
# `pm2 start` is idempotent via `pm2 restart` after the first run.
|
||||
pm2 delete route-commerce 2>/dev/null || true; \
|
||||
PORT=3100 HOSTNAME=0.0.0.0 pm2 start scripts/start-standalone.cjs --name route-commerce --interpreter /home/tyler/.cache/act/tool_cache/node/22.22.3/x64/bin/node 2>&1 | tail -3 && \
|
||||
pm2 save && sleep 4 && \
|
||||
curl -fsS http://localhost:3100/api/health/db-schema >/dev/null || { echo 'Health check failed after start - schema not applied (see plan)'; exit 1; }"
|
||||
|
||||
echo "Deployed successfully"
|
||||
Reference in New Issue
Block a user