-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
67 lines (56 loc) · 1.97 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
const express=require('express');
const morgan=require('morgan');
const path = require('path');
const requestIp=require('request-ip');
const rateLimit=require('express-rate-limit');
const helmet=require('helmet');
const xss=require('xss-clean');
const hpp=require('hpp');
const cookieParser=require('cookie-parser');
const cors=require('cors');
const AppError=require('./utils/appError');
const globalErrorHandler = require('./controllers/errorController');
const subjectRouter=require('./routes/subectRoutes');
const classRouter=require('./routes/classRoutes');
const marksRouter=require('./routes/marksRoutes')
const programRouter=require('./routes/programRoutes');
const userRouter=require('./routes/userRoutes');
const batchRouter=require('./routes/batchRoutes');
const notificationRouter=require('./routes/notificationRoutes');
const postRouter=require('./routes/postRoutes');
const deptRouter=require('./routes/deptRoutes');
const app=express();
app.use(express.static(path.join(__dirname, 'build')));
app.use(cors())
app.use(helmet());
app.use(requestIp.mw());
if (process.env.NODE_ENV==='development'){
app.use(morgan('dev'));
}
const limiter=rateLimit({
max:1000,
windowMs:60*60*1000,
message:'Too many requests from this IP, please try later'
});
app.use('/api',limiter);
app.use(express.json({limit:'10kb'}));
app.use(cookieParser());
app.use(xss());
app.use(hpp());
app.use('/api/subject',subjectRouter);
app.use('/api/class',classRouter);
app.use('/api/marks',marksRouter);
app.use('/api/program',programRouter);
app.use('/api/user',userRouter);
app.use('/api/batch',batchRouter);
app.use('/api/notification',notificationRouter);
app.use('/api/post',postRouter);
app.use('/api/dept',deptRouter);
app.all('/api/*', (req, res, next) => {
next(new AppError(`Can't find ${req.originalUrl} on this server!`, 404));
});
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.use(globalErrorHandler);
module.exports=app;