-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (65 loc) · 2.65 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
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
// importing core modules
import fs from 'fs';
import path from 'path'
// importing 3rd party modules
import express from "express";
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import dotenv from 'dotenv';
//importing routes
import systemAdminRoute from "./src/routes/admin/systemAdminRoute";
//regional routes
import regionalAdminRoute from "./src/routes/regional/regionalAdminRoute";
import regionalOfficialsRoute from './src/routes/regional/regionalOfficialsRoute';
import regionalCurriculum from './src/routes/regional/regionalCurriculumRoute';
import regionalCourseContent from './src/routes/regional/regionalCourseContentRoute';
import workingPathRoute from './src/routes/regional/workingPathRoute';
//school routes
import schoolAdminRoute from "./src/routes/school/schoolAdminRoute";
import schoolOfficialsRoute from './src/routes/school/schoolOfficialsRoute';
import schoolCurriculum from './src/routes/school/schoolCurriculumRoute';
import schoolCourseContent from './src/routes/school/schoolCourseContentRoute';
import schoolCompetition from './src/routes/school/schoolCompetitionRoute';
import schoolClass from './src/routes/school/schoolClassRoute';
import schoolTestBank from './src/routes/school/schoolTestBankRoute';
//initialing express
const app = express();
//3rd party middlewares
const accessLogStream = fs.createWriteStream(__dirname + '/config/access.log', { flags: 'a' });
app.use(morgan('combined', { stream: accessLogStream }));
app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
app.use(cors());
dotenv.config();
//applying routes
app.use('/api/admin', systemAdminRoute);
app.use('/api/reb/admin', regionalAdminRoute);
app.use('/api/reb/officials', regionalOfficialsRoute);
app.use('/api/reb/curriculum', regionalCurriculum);
app.use('/api/reb/courseContent', regionalCourseContent);
app.use('/api/reb/workingPath', workingPathRoute);
// applying school routes
app.use('/api/school/admin', schoolAdminRoute);
app.use('/api/school/officials', schoolOfficialsRoute);
app.use('/api/school/curriculum', schoolCurriculum);
app.use('/api/school/courseContent', schoolCourseContent);
app.use('/api/school/competition', schoolCompetition);
app.use('/api/school/schoolClass', schoolClass);
app.use('/api/school/schoolTestBank', schoolTestBank);
//error handling
app.use((req, res, next) => {
const err = new Error("Not found!");
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.json({
message: err.message
});
});
export default app;