-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
59 lines (50 loc) · 1.52 KB
/
server.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
const express = require('express');
const connectDB = require('./config/db');
const cors = require('cors');
const session = require('express-session');
const bodyParser = require('body-parser');
const path = require('path');
const status = require('express-status-monitor');
require('dotenv').config();
const app = express();
connectDB();
app.use(express.json());
app.use(
cors({
origin: '*',
}),
);
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
app.use('/public', express.static('public'));
app.use((req, res, next) => {
res.setHeader(
"Content-Security-Policy",
"default-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"
);
next();
});
// @route GET home/:name
// @desc home page render
// @access private
app.get('/', (req, res) => {
res.send('home');
});
// Set EJS as the view engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// Use the routes
app.use('/api/anubhav/', require('./routes/blog/blogs'));
app.use('/api/anubhav/', require('./routes/feedbacks'));
app.use('/api/anubhav/', require('./routes/reqarticle'));
app.use('/api/anubhav/', require('./routes/writeArticle'));
app.use('/admin/', require('./routes/admin/controlCenter'));
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));