From f08c513bbe0afb4a0e456ec94cf924bf2f97d21a Mon Sep 17 00:00:00 2001 From: dmy Date: Sun, 18 Jan 2026 15:44:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加开发和生产环境变量文件 更新前端构建命令以使用不同模式 优化部署脚本中的前端部署路径 在认证守卫中添加日志记录 --- .gitignore | 5 ++++- frontend/{.env => .env.development} | 3 +++ frontend/.env.production | 5 +++++ frontend/package.json | 4 ++-- src/common/auth/auth.guard.ts | 12 ++++++++++++ src/scripts/deploy.ts | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) rename frontend/{.env => .env.development} (58%) create mode 100644 frontend/.env.production diff --git a/.gitignore b/.gitignore index a6210de..68a807c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ widget/looker/frontend/src/assets/fonts/OFL.txt dist-electron unpackage .cursor -qingyun \ No newline at end of file +qingyun +plan +.trae +plans \ No newline at end of file diff --git a/frontend/.env b/frontend/.env.development similarity index 58% rename from frontend/.env rename to frontend/.env.development index 40e3e3c..f77d71b 100644 --- a/frontend/.env +++ b/frontend/.env.development @@ -1,2 +1,5 @@ # ARK API Key (用于 AI 推荐) VITE_ARK_API_KEY=a63d58b6-cf56-434b-8a42-5c781ba0822a + +# 后端 API 地址 +VITE_API_BASE_URL=http://localhost:3000/ diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 0000000..0d810f3 --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1,5 @@ +# ARK API Key (用于 AI 推荐) +VITE_ARK_API_KEY=a63d58b6-cf56-434b-8a42-5c781ba0822a + +# 后端 API 地址 +VITE_API_BASE_URL=http://139.180.190.142:3000/ diff --git a/frontend/package.json b/frontend/package.json index 0cf7659..2eef1ab 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,8 +5,8 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vue-tsc -b && vite build", - "build:watch": "concurrently \"vue-tsc -b --watch\" \"vite build --watch\"", + "build": "vue-tsc -b && vite build --mode production", + "build:watch": "concurrently \"vue-tsc -b --watch\" \"vite build --watch --mode development\"", "preview": "vite preview" }, "dependencies": { diff --git a/src/common/auth/auth.guard.ts b/src/common/auth/auth.guard.ts index fc47347..9ff89c5 100644 --- a/src/common/auth/auth.guard.ts +++ b/src/common/auth/auth.guard.ts @@ -3,6 +3,7 @@ import { ExecutionContext, Injectable, UnauthorizedException, + Logger, } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Request } from 'express'; @@ -10,6 +11,8 @@ import { UsersService } from '../../users/users.service'; @Injectable() export class AuthGuard implements CanActivate { + private readonly logger = new Logger(AuthGuard.name); + constructor( private configService: ConfigService, private usersService: UsersService, @@ -22,6 +25,8 @@ export class AuthGuard implements CanActivate { const enableBasicAuth = this.configService.get('ENABLE_BASIC_AUTH') === 'true'; + this.logger.log(`Basic Auth enabled: ${enableBasicAuth}`); + if (!enableBasicAuth) { // 如果未启用 Basic Auth,允许所有访问 return true; @@ -31,6 +36,7 @@ export class AuthGuard implements CanActivate { const authHeader = request.headers['authorization'] as string; if (!authHeader || !authHeader.startsWith('Basic ')) { + this.logger.warn('Missing or invalid Authorization header'); throw new UnauthorizedException('Missing or invalid Authorization header'); } @@ -42,16 +48,22 @@ export class AuthGuard implements CanActivate { const [username, password] = credentials.split(':'); if (!username || !password) { + this.logger.warn('Invalid credentials format'); throw new UnauthorizedException('Invalid credentials format'); } + this.logger.log(`Attempting login for user: ${username}`); + // 验证用户 const user = await this.usersService.validateUser(username, password); if (!user) { + this.logger.warn(`Login failed for user: ${username} - Invalid username or password`); throw new UnauthorizedException('Invalid username or password'); } + this.logger.log(`User ${username} logged in successfully`); + // 将用户信息附加到请求对象 (request as any).user = user; diff --git a/src/scripts/deploy.ts b/src/scripts/deploy.ts index ff7b901..ce1fdbf 100644 --- a/src/scripts/deploy.ts +++ b/src/scripts/deploy.ts @@ -38,7 +38,7 @@ const config = { const destinations = { server: '/root/bidding/publish/server', - frontend: '/root/bidding/publish/frontend', + frontend: '/root/bidding/publish/frontend/dist', src: '/root/bidding/', };