Require Next.js standalone output in website AI prompt and deploy.
Document mandatory output: "standalone" for shared-VM RAM, and align websites-agent deploy to prefer .next/standalone/server.js. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
b1dcecc468
commit
4823cf97f6
@@ -212,16 +212,45 @@ NODE
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "no standalone output — using next start (legacy)"
|
||||
# Vinext (Vite production server) or legacy `next start`.
|
||||
# Detect Vinext from package.json / CLI — do not assume every Next-looking
|
||||
# app has a `.next` production build (vinext writes `dist/` instead).
|
||||
uses_vinext=false
|
||||
if node -e '
|
||||
const fs = require("fs");
|
||||
const p = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
||||
const d = Object.assign({}, p.dependencies || {}, p.devDependencies || {});
|
||||
const s = String((p.scripts || {}).start || "");
|
||||
const ok = Boolean(d.vinext) || s.includes("vinext") || fs.existsSync("node_modules/vinext/dist/cli.js");
|
||||
process.exit(ok ? 0 : 1);
|
||||
'; then
|
||||
uses_vinext=true
|
||||
fi
|
||||
|
||||
if $uses_vinext; then
|
||||
if [[ ! -d dist ]]; then
|
||||
echo "vinext project but dist/ is missing — build did not produce a production bundle"
|
||||
write_status "failed" "vinext build produced no dist/"
|
||||
exit 1
|
||||
fi
|
||||
echo "no Next standalone output — using vinext start"
|
||||
elif [[ -f .next/BUILD_ID ]]; then
|
||||
echo "no standalone output — using next start (legacy)"
|
||||
else
|
||||
echo "build produced neither .next/standalone, Vinext dist/, nor .next/BUILD_ID"
|
||||
write_status "failed" "no production server output (need Next standalone, BUILD_ID, or vinext dist/)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Reset cwd/script in case a previous deploy used standalone. Do not
|
||||
# `pm2 restart --update-env`: the deploy agent has PORT=9050 and that
|
||||
# leaks into the site, so nginx (site port) gets 502.
|
||||
SLUG="$SLUG" ROOT="$ROOT" ECOSYSTEM="$ECOSYSTEM" node <<'NODE'
|
||||
VINEXT="$uses_vinext" SLUG="$SLUG" ROOT="$ROOT" ECOSYSTEM="$ECOSYSTEM" node <<'NODE'
|
||||
const fs = require('fs');
|
||||
const path = process.env.ECOSYSTEM;
|
||||
const slug = process.env.SLUG;
|
||||
const root = process.env.ROOT;
|
||||
const usesVinext = process.env.VINEXT === 'true';
|
||||
let cfg = { apps: [] };
|
||||
try {
|
||||
delete require.cache[require.resolve(path)];
|
||||
@@ -243,7 +272,9 @@ const port =
|
||||
[fromEnv, fromArgs].find((p) => Number.isFinite(p) && p > 0 && p !== 9050) || 3005;
|
||||
|
||||
app.cwd = root;
|
||||
app.script = 'node_modules/next/dist/bin/next';
|
||||
app.script = usesVinext
|
||||
? 'node_modules/vinext/dist/cli.js'
|
||||
: 'node_modules/next/dist/bin/next';
|
||||
app.args = 'start --hostname 127.0.0.1 --port ' + port;
|
||||
app.env = {
|
||||
NODE_ENV: 'production',
|
||||
@@ -276,13 +307,25 @@ lines.push(' ],');
|
||||
lines.push('};');
|
||||
lines.push('');
|
||||
fs.writeFileSync(path, lines.join('\n'));
|
||||
console.log('ecosystem updated for next start:', slug, 'port', port);
|
||||
console.log(
|
||||
'ecosystem updated for',
|
||||
usesVinext ? 'vinext start' : 'next start',
|
||||
':',
|
||||
slug,
|
||||
'port',
|
||||
port,
|
||||
);
|
||||
NODE
|
||||
|
||||
pm2 delete "$SLUG" || true
|
||||
pm2 start "$ECOSYSTEM" --only "$SLUG"
|
||||
pm2 save || true
|
||||
|
||||
echo "==== $(date -u +%Y-%m-%dT%H:%M:%SZ) deploy ok: $SLUG ===="
|
||||
write_status "success" "Deployed origin/$BRANCH"
|
||||
if $uses_vinext; then
|
||||
echo "==== $(date -u +%Y-%m-%dT%H:%M:%SZ) deploy ok (vinext): $SLUG ===="
|
||||
write_status "success" "Deployed origin/$BRANCH (vinext)"
|
||||
else
|
||||
echo "==== $(date -u +%Y-%m-%dT%H:%M:%SZ) deploy ok: $SLUG ===="
|
||||
write_status "success" "Deployed origin/$BRANCH"
|
||||
fi
|
||||
trap - ERR
|
||||
|
||||
Reference in New Issue
Block a user