-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (62 loc) · 1.97 KB
/
index.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
78
79
80
81
// #Index
//
// Main module for SenseBase server..
/*jslint node: true */
'use strict';
var fs = require('fs'),
http = require('http'),
flash = require('connect-flash'),
express = require('express');
var utils = require('./lib/utils'), proxied = require('./lib/proxy-rewrite.js'), pageCache = require('./lib/pageCache.js'),
pubsub = require('./lib/pubsub.js'), auth = require('./lib/auth'), indexer = require('./lib/indexer.js');
exports.setup = setup;
// Start server with configuration.
exports.start = function(context, callback) {
setup(context);
// Express stuff.
var app = express();
var actions = require('./lib/app-actions.js');
app.configure(function() {
app.use(express.cookieParser());
app.use(express.bodyParser());
// app.use(express.logger({stream: GLOBAL.config.logStream}));
app.use(express.methodOverride());
app.use(express.session({ secret: 'popsicle-fish' }));
app.use(flash());
app.use(actions);
app.use(app.router);
app.enable('trust proxy');
});
var server = app.listen(GLOBAL.config.HTTP_PORT);
pubsub.start(server);
if (GLOBAL.config.PROXY_PORT) {
var filterProxy = require('filter-proxy');
proxied.PROXY_PORT = GLOBAL.config.PROXY_PORT;
filterProxy.start(proxied);
}
// Interactive command line.
var repl = require('repl');
var r = repl.start({ prompt: GLOBAL.config.project + "> ", useGlobal: true});
if (callback) {
callback();
}
};
// Set up the GLOBAL environment with configuration and services
//
// Defaults to directory config and users if no context is passed.
//
// pubsub will need to be started on its own.
function setup(context) {
if (GLOBAL.config) {
console.log('already configured');
console.trace();
return;
}
if (!context) {
context = require('./config.js');
}
GLOBAL.config = context.config;
var svc = { pubsub: pubsub, auth: auth, indexer: indexer, pageCache: pageCache };
GLOBAL.svc = svc;
auth.setupUsers(GLOBAL, context.logins);
}