-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (33 loc) · 1.12 KB
/
Copy pathapp.js
File metadata and controls
41 lines (33 loc) · 1.12 KB
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
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const fs = require('fs').promises;
const routes = require('./src/routes');
const http = require('http');
const socketIO = require('socket.io');
const socketService = require('./src/services/socketService');
const app = express();
const server = http.createServer(app);
const port = 3002;
// Initialize socket service with server
socketService.initialize(server);
// Middleware
app.use(bodyParser.json());
app.use(express.static('public'));
// Ensure sourcecodes directory exists
const sourcecodesDir = path.join(__dirname, 'sourcecodes');
fs.mkdir(sourcecodesDir, { recursive: true }).catch(console.error);
// Mount API routes
app.use('/api', routes);
// Serve main page
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: 'Something went wrong!' });
});
server.listen(port, () => {
console.log(`Git Checker app listening at http://localhost:${port}`);
});