-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
56 lines (42 loc) · 1.52 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
56
var fs = require('fs');
var secureFilters = require('secure-filters');
var express = require('express');
var session = require('express-session');
var bodyParser = require('body-parser');
var appPrivate = require('./app-private');
var middleware = require('./api/middleware');
var auth = require('./api/auth');
var streams = require('./api/streams');
var app = express();
var postParser = bodyParser.urlencoded({extended: false});
app.disable('x-powered-by');
app.use(express.static('public'));
app.use(session({
name: 's',
cookie: {
maxAge: 1000 * 60 * 120
},
secret: appPrivate.secret,
resave: false,
saveUninitialized: false
}));
app.get('/api/getData', middleware.requireLogin, streams.getData);
app.post('/api/setStreamData', middleware.requireLogin, postParser, streams.setStreamData);
app.post('/api/createUser', postParser, auth.createUser);
app.post('/api/loginUser', postParser, auth.loginUser);
app.post('/api/logoutUser', middleware.requireLogin, postParser, auth.logoutUser);
app.get('\/*', function(req, res) {
fs.readFile('source/templates/base.html', {encoding: 'utf8'}, function(err, template) {
var user = (req.session.user ? "'" + secureFilters.js(req.session.user.email) + "'" : null),
payload = template.replace('{{user}}', user);
res.send(payload);
});
});
app.use(function(req, res, next) {
res.status(404).send('404');
});
var server = app.listen(1337, function() {
var host = server.address().address;
var port = server.address().port;
console.log('Server running at http://%s:%s', host, port);
});