-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
74 lines (55 loc) · 1.61 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 7070));
var pageData = {
"javascriptsBase": "/javascripts",
"stylesheetsBase": "/stylesheets",
"imagesBase": "/images"
};
app.use('/', express.static(__dirname + '/resources/public'));
app.set('view engine', 'jade');
app.set('views', './assets/jade');
function beforeAllFilter(req, res, next) {
app.locals.pretty = true;
next();
}
app.all('*', beforeAllFilter);
function customRender(res, template, data) {
res.render(template, data, function (err, html) {
var cleanHTML = html.replace(/>!/g, '>');
res.send(cleanHTML);
});
}
app.all('/', function(req, res){
customRender(res, 'sign-in', pageData);
});
app.get(['/index', '/feed'], function(req, res){
customRender(res, 'feed', pageData);
});
app.get('/empty-feed', function(req, res){
customRender(res, 'empty-feed', pageData);
});
app.get('/routes', function(req, res){
customRender(res, 'routes', pageData);
});
app.get('/sign-in', function(req, res){
customRender(res, 'sign-in', pageData);
});
app.get('/create-account', function(req, res) {
customRender(res, 'create-account', pageData);
});
app.get('/customise-feed', function(req, res) {
customRender(res, 'customise-feed', pageData);
});
app.get('/error-500', function(req, res) {
customRender(res, 'error-500', pageData);
});
app.get('/library', function(req, res) {
customRender(res, 'library', pageData);
});
app.get('/sign-out', function(req, res) {
res.redirect('./');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});