-
Notifications
You must be signed in to change notification settings - Fork 1
/
boot.js
72 lines (66 loc) · 2.72 KB
/
boot.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
var path = require("path");
var underscore = require("underscore");
var http = require("http");
var express = require("express");
var assetbuilder = require("asset_builder");
var passport = require("passport");
var AsyncRunner = require("async_runner");
var app = require(path.join(__dirname, "config", "app"));
var db = require(path.join(app.root, "config", "database"));
var authentication = require(path.join(app.root, "config", "authentication"));
var settings = require(path.join(app.root, "config", "settings"));
var socketRoutes = require(path.join(app.root, "app", "socket_routes"));
var httpRoutes = require(path.join(app.root, "app", "http_routes"));
var emberPreprocessor = require(path.join(app.root, "app", "lib", "preprocessors", "ember_preprocessor"));
var Itunes = require(path.join(app.root, "app", "lib", "application_interfaces", "itunes"));
var Spotify = require(path.join(app.root, "app", "lib", "application_interfaces", "spotify"));
var Airfoil = require(path.join(app.root, "app", "lib", "application_interfaces", "airfoil"));
var sessionStore = new express.session.MemoryStore;
function initExpress() {
var application = express();
var server = http.createServer(application);
var router = express
application.configure(function() {
this.use(express.errorHandler({
showStack: true,
dumpExceptions: true
}));
this.use(assetbuilder.middleware);
this.use(express.static(path.join(app.root, "public")));
this.use(express.bodyParser());
this.use(express.methodOverride());
this.use(express.cookieParser());
this.use(express.session(underscore.extend({store: sessionStore}, settings.session)));
this.use(passport.initialize());
this.use(passport.session());
this.set("views", path.join("app", "views"));
this.set("view engine", "jade");
this.set("view options", {layout: false});
authentication(application);
httpRoutes(application);
});
assetbuilder.registerViewHelpers(application);
assetbuilder.registerPreprocessor(emberPreprocessor);
assetbuilder.configure({ env: app.env });
console.log("app running on " + app.port + " in " + app.env);
server.listen(app.port);
return server;
};
// Initialize database before booting app
db.open(function(error) {
if (error) throw error;
runner = new AsyncRunner(function() {
socketRoutes(initExpress(), sessionStore);
});
runner.run({}, [
function(element, hollaback) {
Itunes.launch(hollaback);
},
function(element, hollaback) {
Spotify.launch(hollaback);
},
function(elemnt, hollaback) {
Airfoil.launch(hollaback);
}
]);
});