-
Notifications
You must be signed in to change notification settings - Fork 0
/
whattoeat.js
65 lines (52 loc) · 1.42 KB
/
whattoeat.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
/**
* liby.me.js
*/
var express = require("express");
var config = require("./server/data/config.json");
function setDateTime() {
require("./server/module/datetime.js")();
}
function setCache(server) {
server.enable('view cache');
}
function setCookie(server) {
var cookieParser = require("cookie-parser");
server.use(cookieParser());
}
function setRenderEngine(server) {
server.set("views", __dirname + "/public");
server.engine(".html", require("ejs").__express);
server.set('view engine', "html");
}
function setRoute(server) {
setDefaultPage(server);
setStaticField(server);
setPageHandler(server);
}
function setDefaultPage(server) {
server.get("/", function (req, res) {
res.redirect("/" + config["default_page"]);
});
}
function setStaticField(server) {
config["static_field"].forEach(function (obj, number) {
server.use(obj, express.static(__dirname + "/public/" + obj));
});
}
function setPageHandler(server) {
require("./server/module/route.js").set(server);
}
function setAjax(server) {
require("./server/module/ajax.js").set(server);
}
(function () {
var server = express();
setDateTime();
setCookie(server);
setRenderEngine(server);
setRoute(server);
setAjax(server);
server.listen(config['port'], function () {
console.log(config['name'] + ' Server Now Listening to Port ' + config['port']);
});
})();