forked from sociam/panoptes-researcher-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
48 lines (41 loc) · 1.63 KB
/
run.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
/**
* Panoptes Researcher Dashboard run script
* Run by invoking 'npm start'
*/
var express = require('express');
var app = express();
var httpServer = require('http').Server(app);
var mongoose = require('mongoose');
var env = process.env;
// stop stupid mongoose warnings
mongoose.Promise = global.Promise;
// Fetch configuration variables from package.json, or use sensible defaults
let makePath = (p) => __dirname + '/' + p;
let httpPort = env.npm_package_config_port || 8080;
let mongo = {
'host': env.npm_package_config_mongo_host || 'localhost',
'db': env.npm_package_config_mongo_db || 'zoo_panoptes'
};
let mongoURL = 'mongodb://' + mongo.host + '/' + mongo.db;
let paths = {
'module': makePath(env.npm_package_config_paths_modules || 'node_modules'),
'static': makePath(env.npm_package_config_paths_static || 'frontend/static'),
'templates': makePath(env.npm_package_config_paths_templates || 'frontend/templates')
};
let pusherSocket = env.npm_package_pusher_socket || '79e8e05ea522377ba6db';
// Create MongoDB connection
let db = mongoose.createConnection(mongoURL);
// Create and kick off data service
console.log('Kicking off data service...');
var dataService = require('./backend/data-service.js');
dataService.start(db, mongo, pusherSocket);
// Create and kick off API service
console.log('Kicking off API service...');
var apiService = require('./backend/api-service.js');
apiService.start(db, app);
// Create and kick off web service
console.log('Kicking off web service...');
var webService = require('./backend/web-service.js');
webService.start(app, paths);
// Set listening port for HTTP server
httpServer.listen(httpPort);