-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
38 lines (31 loc) · 1.04 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
const express = require('express');
const bodyParser = require('body-parser');
const db = require('./util/database');
const errorHandler = require('./util/error-handler');
const jwt = require('./util/jwt');
var cors = require('cors')
const path = require('path');
const helmet = require('helmet')
const mongoSanitize = require('express-mongo-sanitize')
const app = express();
app.use(helmet())
const port = process.env.PORT || 80;
app.use(cors())
app.use(bodyParser.urlencoded({ extended: true}));
app.use(express.json({limit: '10kb'}));
app.use(mongoSanitize());
//Serve static files
app.use(express.static(path.join(__dirname, 'public')));
app.use(jwt());
const userRoutes = require('./routes/user');
const questionRoutes = require('./routes/question');
const quizRoutes = require('./routes/quiz');
//Handling User Authentication
app.use('/user', userRoutes);
app.use('/question', questionRoutes);
app.use('/quiz', quizRoutes);
//Handling Errors
app.use(errorHandler);
//Server Running
app.listen(port);
console.log("Server listening on port "+ port);