From e6d814ff7452dc9e6ee2d98d6c702629cfd866d5 Mon Sep 17 00:00:00 2001 From: patdelphi Date: Tue, 19 Aug 2025 18:55:08 +0800 Subject: [PATCH] Fix Koyeb deployment configuration - Update build command to use pnpm instead of npm - Fix frontend build process in Koyeb config - Update API URL configuration for production - Fix database initialization in Dockerfile - Ensure proper static file serving for SPA --- .koyeb/koyeb.yaml | 4 ++-- Dockerfile | 2 +- src/lib/localApi.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.koyeb/koyeb.yaml b/.koyeb/koyeb.yaml index 7d018a2..5db096a 100644 --- a/.koyeb/koyeb.yaml +++ b/.koyeb/koyeb.yaml @@ -6,8 +6,8 @@ services: type: web git: branch: master - build_command: npm ci - run_command: npm start + build_command: npm install -g pnpm@9.0.0 && pnpm install --frozen-lockfile && pnpm run build + run_command: pnpm start instance_type: nano ports: - port: 8000 diff --git a/Dockerfile b/Dockerfile index a9ab2e4..5f79368 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,4 @@ ENV PORT=8000 EXPOSE 8000 # 初始化数据库并启动应用 -CMD ["sh", "-c", "pnpm run db:init && pnpm start"] \ No newline at end of file +CMD ["sh", "-c", "node server/scripts/initDatabase.cjs && node server/index.cjs"] \ No newline at end of file diff --git a/src/lib/localApi.ts b/src/lib/localApi.ts index 0ca113e..006a5a1 100644 --- a/src/lib/localApi.ts +++ b/src/lib/localApi.ts @@ -3,7 +3,8 @@ // 强制在开发环境使用正确的后端地址 const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || - (import.meta.env.DEV ? 'http://localhost:3001/api' : `${window.location.origin}/api`); + (import.meta.env.DEV ? 'http://localhost:3001/api' : + (window.location.hostname.includes('koyeb.app') ? `${window.location.origin}/api` : `${window.location.origin}/api`)); // 调试信息 console.log('API_BASE_URL:', API_BASE_URL);