-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
50 lines (42 loc) · 1.5 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
// SET UP ====================================================================
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const fs = require('fs');
const port = 8080;
const views = __dirname + '/public/views/';
var app = express();
// EXPRESS CONFIGURATION ======================================================
app.set('view engine', 'pug');
app.use(express.static(__dirname + '/public'));
app.use(morgan('dev'));
app.locals.pretty = true; //TODO check in all brow
app.use(bodyParser.urlencoded({'extended':'true'}));
app.use(bodyParser.json());
app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
// SURVEY =====================================================================
app.post('/upload-survey', function(req, res) {
var timestamp = Number(new Date);
req.body['user-id'] = req.ip;
fs.writeFile(
'survey-results/' + timestamp + '.json',
JSON.stringify(req.body),
'utf8',
function () {
res.sendStatus(200);
}
);
});
// ROUTES =====================================================================
app.get('/survey', function(req, res) {
res.render(views+'survey.pug');
});
app.get('/modal/help', function (req, res) {
res.render(views+'modal/help.pug');
});
app.get('/*', function(req, res) {
res.render(views+'index.pug');
});
// LISTEN =====================================================================
app.listen(port);
console.log("App listening on port", port);