diff --git a/Dockerfile b/Dockerfile index 5bcf6d1..dfe131d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,17 @@ # 使用官方Node.js运行时作为基础镜像 FROM node:18-alpine +# 安装pnpm +RUN npm install -g pnpm@9.0.0 + # 设置工作目录 WORKDIR /app -# 复制package.json和package-lock.json -COPY package*.json ./ +# 复制package.json和pnpm-lock.yaml +COPY package.json pnpm-lock.yaml ./ # 安装依赖 -RUN npm ci --only=production +RUN pnpm install --frozen-lockfile --prod # 复制应用代码 COPY . . @@ -24,4 +27,4 @@ ENV PORT=8000 EXPOSE 8000 # 初始化数据库并启动应用 -CMD ["sh", "-c", "npm run db:init && npm start"] \ No newline at end of file +CMD ["sh", "-c", "pnpm run db:init && pnpm start"] \ No newline at end of file diff --git a/server/index.cjs b/server/index.cjs index 6c9f1d0..ecafb77 100644 --- a/server/index.cjs +++ b/server/index.cjs @@ -42,7 +42,11 @@ app.use(helmet({ // CORS配置 app.use(cors({ origin: process.env.NODE_ENV === 'production' - ? ['http://localhost:5173', 'http://localhost:4173'] // 生产环境允许的域名 + ? [ + 'https://common-charyl-patdelphi-75adc386.koyeb.app', + 'http://localhost:5173', + 'http://localhost:4173' + ] // 生产环境允许的域名 : true, // 开发环境允许所有域名 credentials: true, methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], @@ -103,10 +107,11 @@ app.use('*', (req, res) => { app.use(errorHandler); // 启动服务器 -const server = app.listen(PORT, () => { - console.log(`🚀 服务器运行在 http://localhost:${PORT}`); +const server = app.listen(PORT, '0.0.0.0', () => { + console.log(`🚀 服务器运行在 http://0.0.0.0:${PORT}`); console.log(`📊 数据库文件: ${path.resolve('./numerology.db')}`); console.log(`🌍 环境: ${process.env.NODE_ENV || 'development'}`); + console.log(`🏥 健康检查: http://0.0.0.0:${PORT}/api/health`); }); // 优雅关闭