1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import express from 'express';
import { createServer } from 'http';
import { join, dirname } from 'path';
import { existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { setupWebSocket } from './ws.js';
import projectsRouter from './routes/projects.js';
import tasksRouter from './routes/tasks.js';
import pipelineRouter from './routes/pipeline.js';
import gerritRouter from './routes/gerrit.js';
import dashboardRouter from './routes/dashboard.js';
import settingsRouter from './routes/settings.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const app = express();
const server = createServer(app);
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json());
// API routes
app.use('/api/projects', projectsRouter);
app.use('/api/projects/:project/tasks', tasksRouter);
app.use('/api/projects/:project/pipeline', pipelineRouter);
app.use('/api/projects/:project/gerrit', gerritRouter);
app.use('/api/dashboard', dashboardRouter);
app.use('/api/settings', settingsRouter);
// Serve static client in production
const clientDir = join(__dirname, '..', 'client');
if (existsSync(clientDir)) {
app.use(express.static(clientDir));
app.get('*', (_req, res) => {
res.sendFile(join(clientDir, 'index.html'));
});
}
// WebSocket
setupWebSocket(server);
server.listen(PORT, () => {
console.log(`Admin panel running on port ${PORT}`);
});
export { app, server };
|