feat: 添加开发模式支持,本地调试不使用 PM2
实现灵活的进程管理模式,支持开发和生产环境切换: ## 新增功能 - 创建开发模式进程管理服务(dev-process.service.ts) - 使用 Node.js child_process 直接管理 Claude Code 进程 - 添加 USE_PM2 环境变量控制进程管理模式 ## 后端更改 - 新增 dev-process.service.ts:开发模式进程管理 - 更新 instance.service.ts:根据 USE_PM2 选择进程管理方式 - 更新 config:添加 usePM2 配置项 - 修复 TypeScript 类型错误 ## 配置更新 - backend/.env:设置 USE_PM2=false(开发模式) - .env.example:添加 USE_PM2 配置说明 ## 模式对比 **开发模式**(USE_PM2=false): - 使用 child_process 管理进程 - 不需要安装 PM2 - 简化的监控功能 - 适合本地开发 **生产模式**(USE_PM2=true): - 使用 PM2 管理进程 - 完整的监控和自动重启 - 需要安装 PM2 - 适合生产部署 ## 文档更新 - README.md:添加开发/生产模式对比说明 - 更新环境变量表格 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
903dc1e61f
commit
7dca4e93b1
13 files changed
+287
-72
No files matched your search
@@ -13,11 +13,12 @@ declare global {
|
||||
}
|
||||
}
|
||||
|
||||
export function authMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||
export function authMiddleware(req: Request, res: Response, next: NextFunction): void {
|
||||
const authHeader = req.headers.authorization;
|
||||
|
||||
if (!authHeader) {
|
||||
return res.status(401).json({ error: '未提供认证令牌' });
|
||||
res.status(401).json({ error: '未提供认证令牌' });
|
||||
return;
|
||||
}
|
||||
|
||||
const token = authHeader.replace('Bearer ', '');
|
||||
@@ -26,23 +27,25 @@ export function authMiddleware(req: Request, res: Response, next: NextFunction)
|
||||
const decoded = jwt.verify(token, config.accessPassword) as SessionPayload;
|
||||
|
||||
if (!decoded.authenticated) {
|
||||
return res.status(401).json({ error: '无效的认证令牌' });
|
||||
res.status(401).json({ error: '无效的认证令牌' });
|
||||
return;
|
||||
}
|
||||
|
||||
req.session = decoded;
|
||||
next();
|
||||
} catch (error: any) {
|
||||
logger.error('Token 验证失败', error);
|
||||
return res.status(401).json({ error: '无效的认证令牌' });
|
||||
res.status(401).json({ error: '无效的认证令牌' });
|
||||
}
|
||||
}
|
||||
|
||||
// 可选认证(不强制要求登录)
|
||||
export function optionalAuth(req: Request, res: Response, next: NextFunction) {
|
||||
export function optionalAuth(req: Request, _res: Response, next: NextFunction): void {
|
||||
const authHeader = req.headers.authorization;
|
||||
|
||||
if (!authHeader) {
|
||||
return next();
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const token = authHeader.replace('Bearer ', '');
|
||||
|
||||
Reference in new issue
Block a user