-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (42 loc) · 1.63 KB
/
app.js
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
const express = require('express');
const logger = require('./src/utils/logger');
const userRoutes = require('./src/routes/userRoutes');
const movieRoutes = require('./src/routes/movieRoutes');
const serieRoutes = require('./src/routes/serieRoutes');
const searchRoutes = require('./src/routes/searchRoutes');
const bookmarkRoutes = require('./src/routes/bookmarkRoutes');
const favoriteRoutes = require('./src/routes/favoriteRoutes');
const listRoutes = require('./src/routes/listRoutes');
const connectDB = require('./src/config/db');
const errorHandler = require('./src/middlewere/errorHandler');
const dotenv = require('dotenv');
const cors = require('cors');
const app = express();
dotenv.config();
const startServer = async () => {
try {
await connectDB();
app.use(cors({
origin: 'http://localhost:5173',
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization'],
}));
app.use(express.json());
app.use('/api/users', userRoutes);
app.use('/api/movies', movieRoutes);
app.use('/api/series', serieRoutes);
app.use('/api/search', searchRoutes);
app.use('/api/bookmark', bookmarkRoutes);
app.use('/api/favorite', favoriteRoutes);
app.use('/api/lists', listRoutes);
app.use(errorHandler);
const port = process.env.PORT || 2000;
app.listen(port, () => {
logger.info(`App listening at http://localhost:${port}`);
});
} catch (error) {
logger.error(`Failed to start server: ${error.message}`);
process.exit(1);
}
};
startServer();