-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
52 lines (40 loc) · 1.28 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
const express = require('express');
const fileupload = require('express-fileupload');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const helmet = require('helmet');
const mongoSanitize = require('express-mongo-sanitize');
const path = require('path');
const rateLimit = require('express-rate-limit');
const xss = require('xss-clean');
const authController = require('./controllers/authController');
const errorController = require('./controllers/errorController');
const fileRoutes = require('./routes/fileRoutes');
const userRoutes = require('./routes/userRoutes');
const app = express();
app.use(helmet());
// Rate limiter
const limiter = rateLimit({
windowMs: 30 * 60 * 1000,
max: 100,
message: 'Too many requests from this IP. Please try again after 30 minutes',
});
app.use('/api', limiter);
app.use(
cors({
credentials: true,
origin: 'http://127.0.0.1:3000',
})
);
app.use(fileupload());
app.use(express.json());
app.use(cookieParser());
app.use(mongoSanitize());
app.use(xss());
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
}
app.use('/api/v1/users', userRoutes);
app.use('/api/v1/files', authController.protect, fileRoutes);
app.use(errorController);
module.exports = app;