-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
88 lines (74 loc) · 2.35 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Import NPM Modules */
var express = require("express");
var device = require("express-device");
var slashes = require("connect-slashes");
var app = express();
var srv = require('http').createServer(app);
var ejs = require("ejs");
var RedisStore = require("connect-redis")(express);
/* IMPORTANT - Global Variables */
GLOBAL.$ = require("jquery");
GLOBAL.async = require("async");
GLOBAL.config = require("./config");
GLOBAL.lib = require("./lib");
/* Initialize Lib */
lib.init(ejs);
/* Express: Configuration */
app.configure(function() {
//HTML Engine
app.engine("html", ejs.renderFile);
//Global Config
app.set("views", __dirname + "/views");
app.set("view engine", "html");
app.set("view options", { layout: true });
app.set("view cache", true);
app.set("x-powered-by", false);
//Piler Assests
require("./public").init(app, srv);
app.use(require("./public").express);
//Direct Assests
app.use("/favicon", express.static(__dirname + "/public/favicons"));
app.use("/fonts", express.static(__dirname + "/public/fonts"));
app.use("/img", express.static(__dirname + "/public/images"));
//External Addons
app.use(slashes(true));
app.use(device.capture());
//Logger & Cookie
app.use(express.logger("dev"));
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser(config.cookies.session.secret));
app.use(express.session({
key: config.cookies.session.key,
secret: config.cookies.session.secret,
store: new RedisStore({
client: lib.redis
})
}));
//Initialize Models
app.use(lib.models);
//Setup Globals
app.use(require("./routes/globals"));
});
/* Development Only */
app.configure('development', function() {
//Debug Toolbar
require('express-debug')(app, {
theme: __dirname + config.development.debugger.theme,
panels: config.development.debugger.panels
});
});
/* Production Only */
app.configure('production', function() {
//Last Resort Error Handling
process.on('uncaughtException', function(exception) {
console.error(exception);
return false;
});
});
/* Activate Routes */
require("./routes")(app);
/* Start Router */
app.use(app.router);
srv.listen(80);