setup features

This commit is contained in:
2026-01-29 00:24:10 -05:00
parent 787c97a52f
commit 4a6e2c307c
34 changed files with 2891 additions and 71 deletions
+47 -5
View File
@@ -1,17 +1,59 @@
import express from 'express';
import cors from 'cors';
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';
import { initDB } from './db/index.js';
import authRoutes from './routes/auth.js';
import challengeRoutes from './routes/challenges.js';
import predictionRoutes from './routes/predictions.js';
import friendRoutes from './routes/friends.js';
import tmdbRoutes from './routes/tmdb.js';
import leaderboardRoutes from './routes/leaderboard.js';
dotenv.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
// Middleware
app.use(cors());
app.use(express.json());
app.get('/', (req, res) => {
res.json({ message: "What's The Point API" });
// API Routes
app.use('/api/auth', authRoutes);
app.use('/api/challenges', challengeRoutes);
app.use('/api/predictions', predictionRoutes);
app.use('/api/friends', friendRoutes);
app.use('/api/tmdb', tmdbRoutes);
app.use('/api/leaderboard', leaderboardRoutes);
// Health check
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', message: "What's The Point API" });
});
// Serve static frontend files (for production)
const frontendPath = path.join(__dirname, '../../frontend/dist');
app.use(express.static(frontendPath));
// Serve index.html for all non-API routes (SPA support)
app.get('*', (req, res) => {
res.sendFile(path.join(frontendPath, 'index.html'));
});
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`API running on port ${PORT}`);
});
// Initialize database and start server
initDB()
.then(() => {
app.listen(PORT, '0.0.0.0', () => {
console.log(`✅ Server running on port ${PORT}`);
});
})
.catch(err => {
console.error('Failed to start server:', err);
process.exit(1);
});