- Replace Express server with Next.js Route Handlers (16 API routes) - Rewrite index.html SPA as React components (feed, post, admin, modals) - Move style.css to app/globals.css with dark/light themes intact - Add lib/db.js, lib/auth.js (JWT), lib/api.js (client API wrapper) - Server binds 0.0.0.0 by default; host/port configurable via config.js - Uploads served via /api/uploads route (rewrite keeps /uploads/ URLs) - Multi-stage dockerfile using standalone output
# ============================================================
|
||
# Forumlify (Next.js) 生产镜像 — standalone 模式
|
||
# ============================================================
|
||
|
||
# ---- 构建阶段 ----
|
||
FROM node:18-alpine AS builder
|
||
WORKDIR /app
|
||
|
||
# 先装依赖(利用缓存)
|
||
COPY package.json package-lock.json* bun.lock* ./
|
||
RUN npm install
|
||
|
||
# 复制源码并构建
|
||
COPY . .
|
||
RUN npm run build
|
||
|
||
# ---- 运行阶段 ----
|
||
FROM node:18-alpine AS runner
|
||
WORKDIR /app
|
||
ENV NODE_ENV=production
|
||
|
||
# standalone 输出(含 server.js 与最小 node_modules)
|
||
COPY --from=builder /app/.next/standalone ./
|
||
# 静态资源
|
||
COPY --from=builder /app/.next/static ./.next/static
|
||
|
||
# 上传目录
|
||
RUN mkdir -p /app/uploads
|
||
|
||
EXPOSE 3000
|
||
CMD ["node", "server.js"]
|