|
import express from 'express';
|
|
import cors from 'cors';
|
|
import helmet from 'helmet';
|
|
import rateLimit from 'express-rate-limit';
|
|
import dotenv from 'dotenv';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import authRoutes from './routes/auth.js';
|
|
import pptRoutes from './routes/ppt.js';
|
|
import publicRoutes from './routes/public.js';
|
|
import { authenticateToken } from './middleware/auth.js';
|
|
import { errorHandler } from './middleware/errorHandler.js';
|
|
|
|
dotenv.config();
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 7860;
|
|
|
|
|
|
app.use(helmet({
|
|
contentSecurityPolicy: false,
|
|
}));
|
|
|
|
|
|
const limiter = rateLimit({
|
|
windowMs: 15 * 60 * 1000,
|
|
max: 100,
|
|
message: 'Too many requests from this IP, please try again later.'
|
|
});
|
|
app.use('/api', limiter);
|
|
|
|
|
|
app.use(cors({
|
|
origin: process.env.FRONTEND_URL || '*',
|
|
credentials: true
|
|
}));
|
|
|
|
app.use(express.json({ limit: '50mb' }));
|
|
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, '../../frontend/dist')));
|
|
|
|
|
|
app.use('/api/auth', authRoutes);
|
|
app.use('/api/ppt', authenticateToken, pptRoutes);
|
|
app.use('/api/public', publicRoutes);
|
|
|
|
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, '../../frontend/dist/index.html'));
|
|
});
|
|
|
|
|
|
app.use(errorHandler);
|
|
|
|
app.listen(PORT, '0.0.0.0', () => {
|
|
console.log(`Server is running on port ${PORT}`);
|
|
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
|
|
}); |