-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (55 loc) · 2.14 KB
/
index.js
File metadata and controls
67 lines (55 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import 'dotenv/config';
import express from 'express';
import cors from 'cors';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Import routes
import { router as authRoutes } from './src/routes/auth.js';
import { router as roadmapRoutes } from './src/routes/roadmaps.js';
import { router as topicRoutes } from './src/routes/topics.js';
import { router as lessonRoutes } from './src/routes/lessons.js';
import { router as progressRoutes } from './src/routes/progress.js';
import { router as noteRoutes } from './src/routes/notes.js';
import { router as commentRoutes } from './src/routes/commentsNew.js';
import { router as searchRoutes } from './src/routes/search.js';
import { router as submissionRoutes } from './src/routes/submissions.js';
import { errorHandler } from './src/middlewares/index.js';
const app = express();
// Middleware
app.use(cors());
app.use(express.json());
// Serve uploaded files as static assets
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
// API Routes
app.use('/api/auth', authRoutes);
app.use('/api/roadmaps', roadmapRoutes);
app.use('/api/topics', topicRoutes);
app.use('/api/lessons', lessonRoutes);
app.use('/api/progress', progressRoutes);
app.use('/api/notes', noteRoutes);
app.use('/api/comments', commentRoutes);
app.use('/api/search', searchRoutes);
app.use('/api/submissions', submissionRoutes);
// Health check
app.get('/api/health', (_, res) => res.json({ ok: true, timestamp: new Date().toISOString() }));
// 404 handler
app.use((req, res) => {
res.status(404).json({
error: 'Not Found',
message: `Route ${req.method} ${req.path} not found`
});
});
// Centralized error handler
app.use(errorHandler);
const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
console.log(`🚀 API Server running on http://localhost:${PORT}`);
console.log(`📚 Endpoints:`);
console.log(` - GET /api/health`);
console.log(` - POST /api/auth/register`);
console.log(` - POST /api/auth/login`);
console.log(` - GET /api/roadmaps`);
console.log(` - GET /api/search?q=query`);
});