Upload app.js
Browse files- backend/src/app.js +57 -1
backend/src/app.js
CHANGED
@@ -48,6 +48,11 @@ app.use(express.static(path.join(__dirname, '../../frontend/dist')));
|
|
48 |
// 提供数据文件
|
49 |
app.use('/data', express.static(path.join(__dirname, '../../frontend/public/mocks')));
|
50 |
|
|
|
|
|
|
|
|
|
|
|
51 |
// API路由
|
52 |
console.log('Registering API routes...');
|
53 |
|
@@ -65,12 +70,63 @@ app.get('/api/github/status', async (req, res) => {
|
|
65 |
github: validation,
|
66 |
environment: {
|
67 |
tokenConfigured: !!process.env.GITHUB_TOKEN,
|
|
|
68 |
reposConfigured: !!process.env.GITHUB_REPOS,
|
|
|
69 |
nodeEnv: process.env.NODE_ENV
|
70 |
}
|
71 |
});
|
72 |
} catch (error) {
|
73 |
-
res.status(500).json({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
});
|
76 |
|
|
|
48 |
// 提供数据文件
|
49 |
app.use('/data', express.static(path.join(__dirname, '../../frontend/public/mocks')));
|
50 |
|
51 |
+
// 直接提供测试页面路由
|
52 |
+
app.get('/test.html', (req, res) => {
|
53 |
+
res.sendFile(path.join(__dirname, '../../test.html'));
|
54 |
+
});
|
55 |
+
|
56 |
// API路由
|
57 |
console.log('Registering API routes...');
|
58 |
|
|
|
70 |
github: validation,
|
71 |
environment: {
|
72 |
tokenConfigured: !!process.env.GITHUB_TOKEN,
|
73 |
+
tokenPreview: process.env.GITHUB_TOKEN ? `${process.env.GITHUB_TOKEN.substring(0, 8)}...` : 'Not set',
|
74 |
reposConfigured: !!process.env.GITHUB_REPOS,
|
75 |
+
reposList: process.env.GITHUB_REPOS ? process.env.GITHUB_REPOS.split(',') : [],
|
76 |
nodeEnv: process.env.NODE_ENV
|
77 |
}
|
78 |
});
|
79 |
} catch (error) {
|
80 |
+
res.status(500).json({
|
81 |
+
error: error.message,
|
82 |
+
stack: error.stack
|
83 |
+
});
|
84 |
+
}
|
85 |
+
});
|
86 |
+
|
87 |
+
// 添加GitHub测试路由
|
88 |
+
app.get('/api/github/test', async (req, res) => {
|
89 |
+
try {
|
90 |
+
console.log('=== GitHub Connection Test ===');
|
91 |
+
console.log('GITHUB_TOKEN exists:', !!process.env.GITHUB_TOKEN);
|
92 |
+
console.log('GITHUB_REPOS:', process.env.GITHUB_REPOS);
|
93 |
+
|
94 |
+
const { default: githubService } = await import('./services/githubService.js');
|
95 |
+
|
96 |
+
// 测试基本配置
|
97 |
+
const config = {
|
98 |
+
hasToken: !!githubService.token,
|
99 |
+
useMemoryStorage: githubService.useMemoryStorage,
|
100 |
+
repositories: githubService.repositories,
|
101 |
+
apiUrl: githubService.apiUrl
|
102 |
+
};
|
103 |
+
|
104 |
+
console.log('GitHub Service Config:', config);
|
105 |
+
|
106 |
+
// 如果有token,测试连接
|
107 |
+
let connectionTest = null;
|
108 |
+
if (githubService.token) {
|
109 |
+
console.log('Testing GitHub API connection...');
|
110 |
+
connectionTest = await githubService.validateConnection();
|
111 |
+
console.log('Connection test result:', connectionTest);
|
112 |
+
}
|
113 |
+
|
114 |
+
res.json({
|
115 |
+
timestamp: new Date().toISOString(),
|
116 |
+
config,
|
117 |
+
connectionTest,
|
118 |
+
environment: {
|
119 |
+
tokenLength: process.env.GITHUB_TOKEN ? process.env.GITHUB_TOKEN.length : 0,
|
120 |
+
nodeEnv: process.env.NODE_ENV
|
121 |
+
}
|
122 |
+
});
|
123 |
+
|
124 |
+
} catch (error) {
|
125 |
+
console.error('GitHub test error:', error);
|
126 |
+
res.status(500).json({
|
127 |
+
error: error.message,
|
128 |
+
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
|
129 |
+
});
|
130 |
}
|
131 |
});
|
132 |
|