1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/server-impl.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
2016-10-26 10:43:11 +02:00
const { EventEmitter } = require('events');
const logger = require('./logger');
const migrator = require('../migrator');
2016-11-13 21:09:00 +01:00
const getApp = require('./app');
const { startMonitoring } = require('./metrics');
const { createStores } = require('./db');
const { createOptions } = require('./options');
function createApp (options) {
// Database dependecies (statefull)
const stores = createStores(options);
const eventBus = new EventEmitter();
const config = Object.assign({
stores,
eventBus,
}, options);
2016-11-13 15:15:52 +01:00
const app = getApp(config);
2016-06-18 21:53:18 +02:00
const server = app.listen(app.get('port'), () => {
logger.info(`Unleash started on ${app.get('port')}`);
});
startMonitoring(options.serverMetrics, eventBus);
return { app, server, eventBus };
}
function start (opts) {
const options = createOptions(opts);
2016-12-03 13:45:22 +01:00
return migrator({ databaseUrl: options.databaseUrl })
2016-11-13 20:43:29 +01:00
.catch(err => logger.error('failed to migrate db', err))
.then(() => createApp(options))
2016-11-13 20:43:29 +01:00
.catch(err => logger.error('failed creating app', err));
}
module.exports = {
2016-06-18 21:55:46 +02:00
start,
};