forked from bishopZ/heroku-node-express-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
74 lines (57 loc) · 1.77 KB
/
init.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
/* Theater */
global.DIR = process.env.PWD || '/default/path/to/project';
global.PORT = process.env.PORT || 5000;
/* Librarian */
var JSON = require('JSON');
var _ = require('underscore');
// included if you need them \\
// var fs = require('fs'); // disable this in production for extra security
// var http = require('http');
// var $ = require('jQuery');
// var async = require('async');
// var check = require('validator').check,
// sanitize = require('validator').sanitize;
/* Application */
var db = require(global.DIR + '/app/database.js');
var app = require(global.DIR + '/app/application.js');
/* Routing */
// File System Database
app.get('/admin/update/:table', function(req, res){
var table = req.params.table;
db.update(table, res);
});
app.get('/data/:table/:sha?/:format?', function(req, res, next) {
var path = req.params.table;
if (req.params.sha) {
path = req.params.table + '/' + req.params.sha;
}
var data = db.get(path, function(data){
if(data){
if(req.params.format === 'json'){
res.send(data);
} else {
res.render(global.DIR + '/views/value.ejs', data);
}
} else {
res.send('not found');
}
});
});
// Pages
app.get('/', function(req, res, next) {
var data = db.get('version', function(data){
if(data){
res.render(global.DIR + '/views/index.ejs', { version:data.a, siteName:data.siteName });
}
});
});
app.get('/bootswatch', function(req, res){
res.render(global.DIR + '/views/bootswatch.ejs')
})
app.get('/typography', function(req, res){
res.render(global.DIR + '/views/typography.ejs')
})
/* Leader */
app.listen(global.PORT, function() {
console.log("Listening on " + global.PORT);
});