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:
hughhuangandClaude Sonnet 4.5 committed 2026-01-02 23:20:19 +08:00
1 parent 903dc1e61f
commit 7dca4e93b1
13 files changed
+287 -72

No files matched your search

+9 -6
View File
@@ -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 ', '');
+1 -1
View File
@@ -5,7 +5,7 @@ export function errorMiddleware(
error: Error,
req: Request,
res: Response,
next: NextFunction
_next: NextFunction
) {
logger.error('请求处理错误', {
error: error.message,
@@ -14,10 +14,11 @@ export function validate(schema: AnyZodObject) {
} catch (error) {
if (error instanceof ZodError) {
logger.error('验证失败', { errors: error.errors });
return res.status(400).json({
res.status(400).json({
error: '请求数据验证失败',
details: error.errors,
});
return;
}
next(error);
}