-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (45 loc) · 1.48 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
var bodyParser = require('body-parser');
var compression = require('compression');
var cookieParser = require('cookie-parser');
var express = require('express');
var engines = require('consolidate');
var errorHandler = require('errorhandler');
exports.startServer = function(config, callback) {
var app = express();
// setup views and ports
var extension = config.server.views.extension;
app.engine(extension, engines[config.server.views.compileWith]);
app.set('views', config.server.views.path);
app.set('view engine', extension);
app.set('port', process.env.PORT || config.server.port || 3000);
// middleware
app.use(compression());
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
var cachebust = '';
if (process.env.NODE_ENV !== 'production') {
cachebust = '?b=' + (new Date()).getTime();
}
var routeOptions = {
reload: config.liveReload.enabled,
optimize: config.isOptimize != null ? config.isOptimize : false,
cachebust: cachebust
};
var router = express.Router();
router.get('/', function(req, res) {
res.render('index', routeOptions);
});
app.use('/', router);
// start it up
var port = app.get('port');
var server = app.listen(port, function() {
console.log('Express server listening on port ' + port);
});
callback(server);
};