2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
|
|
|
const logger = require('./lib/logger');
|
|
|
|
const defaultDatabaseUri = process.env.DATABASE_URL;
|
2016-06-16 17:27:13 +02:00
|
|
|
|
|
|
|
function start(options) {
|
|
|
|
options = options || {};
|
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
|
2016-06-16 17:27:13 +02:00
|
|
|
// Database dependecies (statefull)
|
2016-06-18 21:53:18 +02:00
|
|
|
const eventDb = require('./lib/db/event')(db);
|
|
|
|
const EventStore = require('./lib/eventStore');
|
|
|
|
const eventStore = new EventStore(eventDb);
|
|
|
|
const featureDb = require('./lib/db/feature')(db, eventStore);
|
|
|
|
const strategyDb = require('./lib/db/strategy')(db, eventStore);
|
2016-06-16 17:27:13 +02:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const config = {
|
2016-06-16 17:27:13 +02:00
|
|
|
baseUriPath: process.env.BASE_URI_PATH || '',
|
|
|
|
port: process.env.HTTP_PORT || process.env.PORT || 4242,
|
2016-06-18 21:53:18 +02:00
|
|
|
db,
|
|
|
|
eventDb,
|
|
|
|
eventStore,
|
|
|
|
featureDb,
|
|
|
|
strategyDb,
|
2016-06-18 09:19:57 +02:00
|
|
|
publicFolder: options.publicFolder
|
2016-06-16 17:27:13 +02:00
|
|
|
};
|
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const app = require('./app')(config);
|
2016-06-16 17:27:13 +02:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const server = app.listen(app.get('port'), () => {
|
|
|
|
logger.info(`unleash started on ${app.get('port')}`);
|
2016-06-16 17:27:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2016-06-18 21:53:18 +02:00
|
|
|
app,
|
|
|
|
server,
|
|
|
|
config
|
2016-06-16 17:27:13 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
process.on('uncaughtException', err => {
|
2016-06-16 17:27:13 +02:00
|
|
|
logger.error('Uncaught Exception:', err.message);
|
|
|
|
logger.error(err.stack);
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = {
|
2016-06-18 21:53:18 +02:00
|
|
|
start
|
2016-06-16 17:27:13 +02:00
|
|
|
};
|