-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
57 lines (45 loc) · 1.32 KB
/
server.js
File metadata and controls
57 lines (45 loc) · 1.32 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import express from 'express';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import apiRoutes from './src/routes/api.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ extended: true }));
// Serve static files from public directory
app.use(express.static(join(__dirname, 'public')));
// API routes
app.use('/api', apiRoutes);
// Serve index.html for root route
app.get('/', (req, res) => {
res.sendFile(join(__dirname, 'public', 'index.html'));
});
// Global error handler
app.use((err, req, res, next) => {
console.error('Server error:', err);
res.status(500).json({
error: 'Server error',
message: process.env.NODE_ENV === 'development'
? err.message
: 'An unexpected error occurred',
});
});
// 404 handler
app.use((req, res) => {
res.status(404).json({
error: 'Not found',
message: 'The requested resource was not found',
});
});
// Start server
app.listen(PORT, () => {
console.log(`
🎬 Subtitle Shifter is running!
Local: http://localhost:${PORT}
Ready to shift some subtitles! 🚀
`);
});
export default app;