- scripts/start.js: copies .next/static to .next/standalone/.next/static before launching the standalone server (prevents CSS 404) - package.json: start script now uses scripts/start.js - Dockerfile: removed fragile manual better-sqlite3 copy (already included in standalone output) - scripts/setup.sh: added local prod option for npm start
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|
const { execSync } = require("child_process")
|
|
const fs = require("fs")
|
|
const path = require("path")
|
|
|
|
const root = path.resolve(__dirname, "..")
|
|
const standaloneDir = path.join(root, ".next", "standalone")
|
|
const staticSrc = path.join(root, ".next", "static")
|
|
const staticDst = path.join(standaloneDir, ".next", "static")
|
|
|
|
if (!fs.existsSync(standaloneDir)) {
|
|
console.error("ERROR: .next/standalone/ not found. Run 'npm run build' first.")
|
|
process.exit(1)
|
|
}
|
|
|
|
if (!fs.existsSync(staticDst)) {
|
|
console.log("Copying static files to standalone output...")
|
|
fs.cpSync(staticSrc, staticDst, { recursive: true })
|
|
}
|
|
|
|
const server = path.join(standaloneDir, "server.js")
|
|
if (!fs.existsSync(server)) {
|
|
console.error("ERROR: server.js not found in standalone output.")
|
|
process.exit(1)
|
|
}
|
|
|
|
process.env.NODE_ENV = "production"
|
|
|
|
const args = process.argv.slice(2)
|
|
const child = require("child_process").spawn("node", [server, ...args], {
|
|
cwd: standaloneDir,
|
|
stdio: "inherit",
|
|
env: {
|
|
...process.env,
|
|
PORT: process.env.PORT || "3000",
|
|
HOSTNAME: process.env.HOSTNAME || "0.0.0.0",
|
|
},
|
|
})
|
|
|
|
child.on("exit", (code) => process.exit(code))
|