-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (43 loc) · 1.6 KB
/
index.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
require('dotenv').config();
const path = require('path'),
express = require('express'),
app = express(),
cors = require('cors'),
helmet = require('helmet'),
errorHandler = require('./controllers/error');
questionRoutes = require('./routes/questions');
const PORT = process.env.PORT || 8080;
app.use(
helmet.contentSecurityPolicy({
directives: {
defaultSrc: ["'self'"],
connectSrc: ["'self'", 'https://mcq-mern-app.herokuapp.com/api'],
frameSrc: ["'self'", 'https://mcq-mern-app.herokuapp.com/api'],
childSrc: ["'self'", 'https://mcq-mern-app.herokuapp.com/api'],
scriptSrc: ["'self'", 'https://mcq-mern-app.herokuapp.com/api'],
styleSrc: [
"'self'",
"'unsafe-inline'",
'https://fonts.googleapis.com'
],
fontSrc: ["'self'", ' data: https://fonts.gstatic.com'],
baseUri: ["'self'"],
},
})
);
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, 'view/build')));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'view/build', 'index.html'));
});
app.use('/api', questionRoutes);
app.use((req, res, next) => {
let err = new Error("Not Found");
err.status = 404;
next(err);
});
app.use(errorHandler);
app.listen(PORT, () => {
console.log(`Server is starting on port ${PORT}`);
});