forked from philbooth/JSComplexity.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
65 lines (55 loc) · 1.65 KB
/
app.js
File metadata and controls
65 lines (55 loc) · 1.65 KB
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
'use strict';
var express = require('express'),
hogan = require('hogan-express'),
http = require('http'),
path = require('path'),
routes = require('./routes'),
partials = require('./views/partials'),
app = express();
initialise();
function initialise () {
app.configure(initialiseAll);
app.configure('development', initialiseDev);
app.configure('production', initialiseLive);
setRouteHandlers();
awaitConnections();
}
function initialiseAll () {
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.set('layout', 'layout');
app.set('partials', partials);
app.enable('view cache');
app.engine('html', hogan);
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware({
src: path.join(__dirname, 'client'),
dest: path.join(__dirname, 'public'),
compress: true
}));
app.use(express.static(path.join(__dirname, 'public')));
}
function initialiseDev () {
app.use(express.errorHandler());
}
function initialiseLive () {
// TODO: Pretty 404, 500 pages
}
function setRouteHandlers () {
var i, route;
for (i = 0; i < routes.length; i += 1) {
route = routes[i];
app[route.method](route.path, route.handler);
}
}
function awaitConnections () {
http.createServer(app).listen(app.get('port'), function () {
console.log('jscomplexity.org running on port ' + app.get('port'));
});
}