Initial commit
This commit is contained in:
commit
b3a51a4115
10336 changed files with 2381973 additions and 0 deletions
49
backend/src/index.ts
Normal file
49
backend/src/index.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
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 legRoutes from './routes/legs';
|
||||
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/legs', legRoutes);
|
||||
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();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue