-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (29 loc) · 1010 Bytes
/
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
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser')
const express = require('express');
const fs = require('fs');
const http = require('http');
const path = require('path');
const route = require('./routes');
const csrf = require('csurf');
const favicon = require('serve-favicon')
let csrfProtection = csrf({ cookie: true });
let app = express();
app.set('view engine', 'ejs');
app.set('views', './views');
app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
app.use(bodyParser.json({limit: '50mb'}));
app.use(cookieParser());
app.all('/api/*', csrfProtection, (req, res, next) => {
res.type('json');
next();
});
route(app);
app.get('/*', csrfProtection, (req, res) => {
res.render('index', { csrfToken: req.csrfToken() });
});
http.createServer(app).listen(3000, () => {
console.log('Server running on 3000...');
});