-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
72 lines (71 loc) · 2.12 KB
/
content.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
const path = require('path');
const fs = require('fs');
const Handlebars = require('handlebars');
const async = require('async');
const helpers = require('./helpers');
const getTemplate = helpers.getTemplate;
const doError = helpers.doError;
const formatPage = helpers.formatPage;
const dataStorage = require('./models/bonspielData');
module.exports = (req, res, next) => {
var reqURI = req.path;
async.waterfall([
callback => {
callback(get(reqURI, req, res) ? true : null);
},
callback => {
callback(get(path.normalize(reqURI + "/index"), req, res) ? true : null);
}
], err => err || next());
function get(reqURI, req, res) {
if (Object.keys(pages).indexOf(reqURI) !== -1) {
pages[reqURI](req, con => {
if (!(con.format === false)) {
res.set({'content-type': 'text/html; charset=UTF-8'});
res.end(formatPage(req, reqURI, con.title, con.content));
} else {
res.set({'content-type': 'text/html; charset=UTF-8'});
res.end(con.content);
}
});
return true;
} else return false;
}
};
var pages = {
"/": (req, cb) => {
isFunction(cb) && cb({content: getTemplate('content/index.handlebars')()});
},
"/about": (req, cb) => {
isFunction(cb) && cb({content: getTemplate('content/about.handlebars')(), title: "About"});
},
"/contact": (req, cb) => {
isFunction(cb) && cb({content: getTemplate('content/contact.handlebars')(), title: "Contact"});
},
"/license": (req, cb) => {
isFunction(cb) && cb({content: getTemplate('content/license.handlebars')(), title: "License"});
},
"/privacy": (req, cb) => {
isFunction(cb) && cb({
content: getTemplate('content/privacy.handlebars')(),
title: "Privacy Policy"
});
},
"/tos": (req, callback) => {
!isFunction(callback) || callback({
content: getTemplate('content/tos.handlebars')(),
title: "Terms of Service"
});
},
"/signup": (req, cb) => {
isFunction(cb) && cb({
content: getTemplate('content/signup.handlebars')(), title: "Sign Up"
});
},
"/login": (req, cb) => {
isFunction(cb) && cb({
content: getTemplate('content/login.handlebars')(), title: "Log In"
});
}
};
var isFunction = Handlebars.Utils.isFunction;