-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
41 lines (32 loc) · 1.04 KB
/
Copy pathserver.js
File metadata and controls
41 lines (32 loc) · 1.04 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
const express = require('express');
const cors = require('cors');
const articlesRouter = require('./routes/articles');
const tagsRouter = require('./routes/tags');
const usersRouter = require('./routes/users');
const app = express();
const PORT = process.env.PORT || 3001;
// Middleware
app.use(cors({ origin: 'http://localhost:5173', credentials: true }));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.use('/api/articles', articlesRouter);
app.use('/api/tags', tagsRouter);
app.use('/api/user', usersRouter);
// Health check
app.get('/api/health', (_req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// 404 handler
app.use((_req, res) => {
res.status(404).json({ error: 'Route not found' });
});
// Global error handler
app.use((err, _req, res, _next) => {
console.error(err.stack);
res.status(500).json({ error: 'Internal server error' });
});
app.listen(PORT, () => {
console.log(`✅ Conduit API running on http://localhost:${PORT}`);
});
module.exports = app;