-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (52 loc) · 1.64 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
'use strict';
var compression = require('compression');
var express = require('express');
var app = express();
var http = require('http').Server(app);
var swig = require('swig');
var swigFilters = require('./swig/filters');
var settings = require('./local_settings');
var fs = require('fs');
var path = require('path');
// make sure we were passed a port
var port = process.argv[2];
if(!port) {
console.error('Usage: npm server <port>');
process.exit(-1);
}
// setup express to use compression
app.use(compression());
// use swig for templates
app.engine('html', swig.renderFile);
app.engine('plist', swig.renderFile);
app.set('views', settings.TEMPLATE_PATH);
app.set('view engine', 'html');
app.set('_settings', settings);
// cache the views?
app.set('view cache', settings.CACHE_TEMPLATES);
swig.setDefaults({ cache: settings.CACHE_TEMPLATES });
// should express serve static?
if(settings.SERVE_STATIC) {
app.use('/static', express.static(settings.STATIC_PATH));
}
// apply the swig filters
swigFilters(swig, {app : app, settings : settings});
app.disable('x-powered-by');
// load the app
var App = require('./app')(app, settings);
app.use('/', App);
// setup the bundle folders.
// for(var app in settings.VALID_BUNDLES) {
// // settings.VALID_BUNDLES[app]
// var baseAppPath = path.join(settings.DATA_DIR, settings.VALID_BUNDLES[app]);
// var buildPath = path.join(baseAppPath, 'builds');
// if (!fs.existsSync(baseAppPath)) {
// fs.mkdir(baseAppPath, function() {
// fs.mkdir(buildPath, function() {});
// });
// }
// }
// run the server
http.listen(parseInt(port, 10), function(){
console.log('listening on *:' + port);
});