fix: standalone start script copies static files automatically

- 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
This commit is contained in:
renato97
2026-07-23 16:25:52 -03:00
parent 25449aa5df
commit 4e9f815a53
4 changed files with 58 additions and 11 deletions
+2 -4
View File
@@ -16,13 +16,11 @@ ENV NODE_ENV=production
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
RUN mkdir -p /app/data/covers && chown -R nextjs:nodejs /app/data
COPY --from=builder /app/public ./public
RUN mkdir .next
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/node_modules/better-sqlite3 ./node_modules/better-sqlite3
RUN mkdir -p /app/data/covers && chown -R nextjs:nodejs /app/data
USER nextjs
EXPOSE 3000
+1 -1
View File
@@ -5,7 +5,7 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"start": "node scripts/start.js",
"lint": "eslint"
},
"dependencies": {
+15 -6
View File
@@ -13,22 +13,31 @@ fi
echo ""
echo "Choose install method:"
echo " 1) Local (npm run dev)"
echo " 2) Docker Compose"
echo " 1) Local dev (npm run dev)"
echo " 2) Local prod (npm run build && npm start)"
echo " 3) Docker Compose (producción)"
echo ""
read -rp "Method [1/2]: " method
read -rp "Method [1/2/3]: " method
if [ "$method" = "2" ]; then
if [ "$method" = "3" ]; then
echo ""
echo "=== Docker build & start ==="
docker compose up -d --build
echo ""
echo "Web running at http://localhost:3000"
elif [ "$method" = "2" ]; then
echo ""
echo "=== Local prod build ==="
npm install
npm run build
echo ""
echo "Run: npm start"
echo "Web running at http://localhost:3000"
else
echo ""
echo "=== Local install ==="
echo "=== Local dev ==="
npm install
echo ""
echo "Run: npm run dev"
echo "Or: npm run build && npm start"
echo "Web running at http://localhost:3000"
fi
+40
View File
@@ -0,0 +1,40 @@
#!/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))