-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (41 loc) · 1.32 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
import cookieParser from 'cookie-parser';
config();
import express from 'express';
import { config } from 'dotenv';
import cors from 'cors';
import morgan from 'morgan';
import errorMiddleware from './middlewares/error.middleware.js';
const app = express();
// Middlewares
// Built-In
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Third-Party
const corsOptions ={
origin:'http://localhost:5173',
credentials:true, //access-control-allow-credentials:true
optionSuccessStatus:200
}
app.use(cors(corsOptions));
app.use(morgan('dev'));
app.use(cookieParser());
// Server Status Check Route
app.get('/ping', (_req, res) => {
res.send('Pong');
});
// Import all routes
import userRoutes from './routes/user.routes.js';
import courseRoutes from './routes/course.routes.js';
import paymentRoutes from './routes/payment.routes.js';
import miscRoutes from './routes/miscellaneous.routes.js';
app.use('/api/v1/user', userRoutes);
app.use('/api/v1/courses', courseRoutes);
app.use('/api/v1/payments', paymentRoutes);
app.use('/api/v1', miscRoutes);
// Default catch all route - 404
app.all('*', (_req, res) => {
res.status(404).send('OOPS!!! 404 Page Not Found');
});
// Custom error handling middleware
app.use(errorMiddleware);
export default app;