Upload app.js
Browse files- backend/src/app.js +43 -0
backend/src/app.js
CHANGED
|
@@ -462,6 +462,49 @@ app.get('/api/github/test', async (req, res) => {
|
|
| 462 |
}
|
| 463 |
});
|
| 464 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
// 添加路由注册日志
|
| 466 |
console.log('Importing route modules...');
|
| 467 |
console.log('Auth routes imported:', !!authRoutes);
|
|
|
|
| 462 |
}
|
| 463 |
});
|
| 464 |
|
| 465 |
+
// 添加仓库初始化端点
|
| 466 |
+
app.post('/api/github/initialize', async (req, res) => {
|
| 467 |
+
try {
|
| 468 |
+
console.log('=== Manual Repository Initialization ===');
|
| 469 |
+
|
| 470 |
+
const { default: githubService } = await import('./services/githubService.js');
|
| 471 |
+
|
| 472 |
+
if (githubService.useMemoryStorage) {
|
| 473 |
+
return res.status(400).json({
|
| 474 |
+
error: 'Cannot initialize repository: using memory storage mode',
|
| 475 |
+
reason: 'GitHub token not configured'
|
| 476 |
+
});
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
const { repoIndex = 0 } = req.body;
|
| 480 |
+
console.log(`Initializing repository at index: ${repoIndex}`);
|
| 481 |
+
|
| 482 |
+
const result = await githubService.initializeRepository(repoIndex);
|
| 483 |
+
|
| 484 |
+
if (result.success) {
|
| 485 |
+
res.json({
|
| 486 |
+
success: true,
|
| 487 |
+
message: 'Repository initialized successfully',
|
| 488 |
+
commit: result.commit,
|
| 489 |
+
timestamp: new Date().toISOString()
|
| 490 |
+
});
|
| 491 |
+
} else {
|
| 492 |
+
res.status(500).json({
|
| 493 |
+
success: false,
|
| 494 |
+
error: result.error,
|
| 495 |
+
reason: result.reason
|
| 496 |
+
});
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
} catch (error) {
|
| 500 |
+
console.error('Repository initialization error:', error);
|
| 501 |
+
res.status(500).json({
|
| 502 |
+
error: error.message,
|
| 503 |
+
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
|
| 504 |
+
});
|
| 505 |
+
}
|
| 506 |
+
});
|
| 507 |
+
|
| 508 |
// 添加路由注册日志
|
| 509 |
console.log('Importing route modules...');
|
| 510 |
console.log('Auth routes imported:', !!authRoutes);
|