-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
58 lines (49 loc) · 1.69 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
var express = require('express')
, bodyParser = require('body-parser')
, engines = require('consolidate')
, compression = require('compression')
, favicon = require('serve-favicon')
, cookieParser = require('cookie-parser')
, errorHandler = require('errorhandler')
;
exports.startServer = function(config, callback) {
var app = express();
// setup views and port
app.set('views', config.server.views.path);
app.engine(config.server.views.extension, engines[config.server.views.compileWith]);
app.set('view engine', config.server.views.extension);
app.set('port', process.env.PORT || config.server.port || 3000);
// middleware
app.use(compression());
// uncomment and point path at favicon if you have one
// app.use(favicon("path to fav icon"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(cookieParser());
app.use(express.static(config.watch.compiledDir));
if (app.get('env') === 'development') {
app.use(errorHandler());
}
// routes
cachebust = '';
if (process.env.NODE_ENV !== "production") {
cachebust = "?b=" + +new Date();
}
var routeOptions = {
reload: config.liveReload.enabled,
optimize: config.isOptimize != null ? config.isOptimize : false,
cachebust: cachebust
};
var router = express.Router()
router.get('/', function(req, res) {
// different routes/pages can just feed different controllers
routeOptions.controller = "blogger";
res.render('index', routeOptions);
});
app.use('/', router);
// start it up
var server = app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
callback(server);
};