49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import 'dotenv/config';
|
|
import express from 'express';
|
|
import cors from 'cors';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { initDatabase } from './config/database.js';
|
|
import authRoutes from './routes/auth.js';
|
|
import roomRoutes from './routes/rooms.js';
|
|
import recordingRoutes from './routes/recordings.js';
|
|
import adminRoutes from './routes/admin.js';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3001;
|
|
|
|
// Middleware
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// Initialize database & start server
|
|
async function start() {
|
|
await initDatabase();
|
|
|
|
// API Routes
|
|
app.use('/api/auth', authRoutes);
|
|
app.use('/api/rooms', roomRoutes);
|
|
app.use('/api/recordings', recordingRoutes);
|
|
app.use('/api/admin', adminRoutes);
|
|
|
|
// Serve static files in production
|
|
if (process.env.NODE_ENV === 'production') {
|
|
app.use(express.static(path.join(__dirname, '..', 'dist')));
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, '..', 'dist', 'index.html'));
|
|
});
|
|
}
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🔴 Redlight server running on http://localhost:${PORT}`);
|
|
});
|
|
}
|
|
|
|
start().catch(err => {
|
|
console.error('❌ Failed to start server:', err);
|
|
process.exit(1);
|
|
});
|