Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,33 @@ COS_BUCKET=your-bucket-name
COS_REGION=ap-guangzhou

# Application Configuration
# 端口配置说明:
# - 如需并行运行多个项目实例,请修改以下端口配置
# - 建议使用不同的端口范围,例如:
# - 实例1: FRONTEND_PORT=8001, BACKEND_PORT=8002
# - 实例2: FRONTEND_PORT=8011, BACKEND_PORT=8012
# - 实例3: FRONTEND_PORT=8021, BACKEND_PORT=8022
#
# 注意:修改端口后,需要同时更新以下配置:
# - NEXT_PUBLIC_API_URL (前端调用后端的地址)
# - CORS_ORIGIN (后端允许的前端地址)
# - AUTH_BASE_URL (认证基础 URL)
BACKEND_PORT=8002
FRONTEND_PORT=8001
NODE_ENV=development

# CORS
# Cors (production example: https://novel.daerai.com)
# 后端允许的前端地址列表,多个地址用逗号分隔
# 开发环境示例: http://localhost:8001
# 生产环境示例: https://novel.daerai.com
# 如需并行运行多个项目,需要添加对应前端地址
CORS_ORIGIN=http://localhost:8001,https://novel.daerai.com

# Authentication Base URL (MUST be set in production)
# Example: https://novel.daerai.com/api/auth
# 认证服务的基础 URL,用于 OAuth 回调等
# 开发环境示例: http://localhost:8002/api/auth
# 生产环境示例: https://novel.daerai.com/api/auth
# 如需并行运行多个项目,需要修改为对应后端端口
AUTH_BASE_URL=http://localhost:8002/api/auth

# LinuxDo OAuth
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ import sandboxRoutes from './routes/sandbox.routes';
const app: Application = express();
const httpServer = createServer(app);
// CORS configuration
const frontendPort = process.env.FRONTEND_PORT || 8001;
const defaultFrontendUrl = `http://localhost:${frontendPort}`;
const allowedOrigins = process.env.CORS_ORIGIN
? process.env.CORS_ORIGIN.split(',').map(origin => origin.trim())
: ['http://localhost:8001', 'tauri://localhost', 'http://tauri.localhost'];
: [defaultFrontendUrl, 'tauri://localhost', 'http://tauri.localhost'];

const corsOptions = {
origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => {
Expand Down
9 changes: 9 additions & 0 deletions apps/frontend/.env.local.example
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# 前端调用后端 API 的地址
# 开发环境示例: http://localhost:8002
# 生产环境示例: https://novel.daerai.com
#
# 如需并行运行多个项目实例,需要修改为对应后端端口
# 例如:
# - 实例1: NEXT_PUBLIC_API_URL=http://localhost:8002
# - 实例2: NEXT_PUBLIC_API_URL=http://localhost:8012
# - 实例3: NEXT_PUBLIC_API_URL=http://localhost:8022
NEXT_PUBLIC_API_URL=http://localhost:8002
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev -p 8001",
"dev": "next dev -p ${FRONTEND_PORT:-8001}",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
Loading