🔧 Fix Cloudflare build issues and restore Docker support

 Cloudflare Pages Fixes:
- Fix IPTV page Suspense boundary issue for static generation
- Resolve ESLint warnings (unused imports, console statements)
- Remove dependency on useSearchParams for static builds
- Improve error handling without console.error

🐳 Docker Support Restored:
- Add complete Docker configuration (Dockerfile, docker-compose.yml)
- Support both basic (localstorage) and Redis deployment modes
- Multi-platform builds (amd64/arm64) via GitHub Actions
- Production-ready with health checks and proper security

📚 Documentation Updates:
- Comprehensive deployment guide for all platforms
- Docker quick start and production examples
- Environment variable documentation
- Updated README with multi-platform support

🎯 Key Improvements:
- Multiple deployment options: Cloudflare + Docker + Vercel
- Better error boundaries and loading states
- Optimized build processes for each platform
- Enhanced developer experience

This fixes the Cloudflare Pages deployment while providing
Docker as an alternative self-hosting option.
This commit is contained in:
Cursor Agent
2025-08-29 05:04:31 +00:00
parent d811fb5aa6
commit b8e1eaab17
9 changed files with 560 additions and 78 deletions
+64
View File
@@ -0,0 +1,64 @@
# ---- 第 1 阶段:安装依赖 ----
FROM --platform=$BUILDPLATFORM node:20-alpine AS deps
# 启用 corepack 并激活 pnpmNode20 默认提供 corepack
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# 仅复制依赖清单,提高构建缓存利用率
COPY package.json pnpm-lock.yaml ./
# 安装所有依赖(含 devDependencies,后续会裁剪)
RUN pnpm install --frozen-lockfile
# ---- 第 2 阶段:构建项目 ----
FROM --platform=$BUILDPLATFORM node:20-alpine AS builder
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# 复制依赖
COPY --from=deps /app/node_modules ./node_modules
# 复制全部源代码
COPY . .
# 设置Docker环境标识
ENV DOCKER_ENV=true
ENV NODE_ENV=production
# For Docker builds, force dynamic rendering to read runtime environment variables.
RUN sed -i "/const inter = Inter({ subsets: \['latin'] });/a export const dynamic = 'force-dynamic';" src/app/layout.tsx
# 生成生产构建
RUN pnpm run build
# ---- 第 3 阶段:生成运行时镜像 ----
FROM node:20-alpine AS runner
# 创建非 root 用户
RUN addgroup -g 1001 -S nodejs && adduser -u 1001 -S nextjs -G nodejs
WORKDIR /app
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
ENV DOCKER_ENV=true
# 从构建器中复制 standalone 输出
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
# 从构建器中复制 scripts 目录
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
# 从构建器中复制 start.js
COPY --from=builder --chown=nextjs:nodejs /app/start.js ./start.js
# 从构建器中复制 public 和 .next/static 目录
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/config.json ./config.json
# 切换到非特权用户
USER nextjs
EXPOSE 3000
# 使用自定义启动脚本,先预加载配置再启动服务器
CMD ["node", "start.js"]