-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
77 lines (62 loc) · 1.92 KB
/
app.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
var express = require('express'),
path = require('path'),
http = require('http'),
sassMiddleware = require('node-sass-middleware'),
mongoose = require('mongoose'),
domain = require('domain'),
jwt = require('jsonwebtoken'),
app = express(),
env = app.get('env'),
config = require(process.env.DEVFLOW_CONFIG || './config')(env),
port = process.env.PORT || config.port,
d = domain.create();
// set config as a global var
global.config = config;
// setup app general settings
app.set('port', port);
app.set('views', path.join(__dirname, 'views'));
app.set('superSecret', config.apiSecret);
// app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.compress());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: config.sessionSecret }));
// setup authentication
require('./auth')(app);
app.use(app.router);
// connect to db
mongoose.connect(config.mongo);
// concat and uglify
require('./compress').compress(env);
// setup sass middleware
app.use(
sassMiddleware({
src: __dirname + '/sass',
dest: __dirname + '/public/styles',
prefix: '/styles',
debug: true
})
);
app.use(express.static(path.join(__dirname, 'public')));
// setup routes
require('./routes')(app);
// Must be after all the routes to catch errors.
app.use(express.errorHandler);
// Init server
var nodeServer = http.createServer(app);
// init sockets
global.sockets = require('./sockets')(nodeServer).sockets;
// init jobs
require('./jobs');
// Init global error catch
d.on('error', function(err) {
console.error(err);
});
// start server
nodeServer.listen(port, function() {
console.log('Devflow server listening on port ' + port);
});