forked from csu-iteam/CS-546-Final-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (47 loc) · 1.56 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
53
54
55
const express = require('express')
const app = express()
const configRoutes = require('./routes')
const exphbs = require('express-handlebars')
const cookie = require('cookie-parser')
const session = require('express-session')
const expressSanitizer = require('express-sanitizer')
const staticpage = express.static(__dirname + '/public')
app.use(cookie())
app.use(express.json())
app.use(expressSanitizer())
app.use('/public', staticpage)
// CORS support settings
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
next();
});
app.use(session({
name: 'UserInformation',
secret: 'UserSecret',
resave: false,
saveUninitialized: true
}))
const handlebarsInstance = exphbs.create({
defaultLayout: 'main',
helpers: {
asJSON: (obj, spacing) => {
if (typeof spacing === 'number')
return new Handlebars.SafeString(JSON.stringify(obj, null, spacing));
return new Handlebars.SafeString(JSON.stringify(obj));
}
}
});
app.use(express.urlencoded({extended: true}))
app.engine('handlebars', exphbs({defaultLayout: 'main'}))
app.set('view engine', 'handlebars')
app.get('/', function (req, res, next) {
req = req.sanitize(req.body)
next()
})
configRoutes(app)
app.listen(3000, () => {
console.log("We've now got a server!")
console.log('Your routes will be running on http://localhost:3000')
})