51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import { createServer } from 'http';
|
|
import { Server } from 'socket.io';
|
|
import { PrismaClient } from '@prisma/client';
|
|
import authRoutes from './routes/auth';
|
|
import gameRoutes from './routes/games';
|
|
import teamRoutes from './routes/teams';
|
|
import routeRoutes from './routes/routes';
|
|
import userRoutes from './routes/users';
|
|
import uploadRoutes from './routes/upload';
|
|
import setupSocket from './socket/index';
|
|
|
|
const app = express();
|
|
const httpServer = createServer(app);
|
|
const io = new Server(httpServer, {
|
|
cors: {
|
|
origin: ['http://localhost:5173', 'http://localhost:3000'],
|
|
methods: ['GET', 'POST']
|
|
}
|
|
});
|
|
|
|
export const prisma = new PrismaClient();
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
app.use('/uploads', express.static('uploads'));
|
|
|
|
app.use('/api/auth', authRoutes);
|
|
app.use('/api/games', gameRoutes);
|
|
app.use('/api/teams', teamRoutes);
|
|
app.use('/api/routes', routeRoutes);
|
|
app.use('/api/users', userRoutes);
|
|
app.use('/api/upload', uploadRoutes);
|
|
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({ status: 'ok' });
|
|
});
|
|
|
|
setupSocket(io);
|
|
|
|
const PORT = process.env.PORT || 3001;
|
|
|
|
httpServer.listen(PORT, () => {
|
|
console.log(`Server running on port ${PORT}`);
|
|
});
|
|
|
|
process.on('SIGINT', async () => {
|
|
await prisma.$disconnect();
|
|
process.exit();
|
|
});
|