-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
86 lines (55 loc) · 1.8 KB
/
Copy pathapp.js
File metadata and controls
86 lines (55 loc) · 1.8 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require('express');
const createError = require('http-errors');
const morgan = require('morgan');
require('dotenv').config();
const connectDB = require('./src/config/db_init.js')
/*routes import*/
const auth= require('./src/api/routes/authRoute.js');
const departement= require('./src/api/routes/departementRoute.js');
const event= require('./src/api/routes/eventRoute.js');
const project= require('./src/api/routes/projectRoute.js');
const ticket= require('./src/api/routes/ticketRoute.js');
const member = require('./src/api/routes/memberRoute')
const badge = require('./src/api/routes/badgeRoute')
const task = require('./src/api/routes/taskRoute')
const notification = require('./src/api/routes/notificationRoute')
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(morgan('dev'));
connectDB();
//Main Route
app.get('/', async (req, res, next) => {
res.send({ message: 'Awesome it works 🐻' });
});
//call routes
app.use('/member', member)
app.use('/badge', badge)
app.use('/task', task)
app.use('/notification', notification)
/*sub apps routes*/
app.use('/auth', auth)
app.use('/projects',project)
app.use('/departements',departement)
app.use('/events',event)
app.use('/tickets', ticket)
app.use((req, res, next) => {
next(createError.NotFound());
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.send({
status: err.status || 500,
message: err.message,
});
});
// if the route is not found
app.use('*', (req, res) => {
res.status(404).json({ message: 'Not Found' });
});
// if the route is not found
app.use('*', (req, res) => {
res.status(404).json({ message: 'Not Found' });
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`🚀 @ http://localhost:${PORT}`));