1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/packages/unleash-api/server-impl.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const logger = require('./lib/logger');
const defaultDatabaseUri = process.env.DATABASE_URL;
2016-07-02 11:54:50 +02:00
function start (options) {
options = options || {};
2016-06-18 21:53:18 +02:00
const db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
// 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-18 21:53:18 +02:00
const config = {
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 21:55:46 +02:00
publicFolder: options.publicFolder,
};
2016-06-18 21:53:18 +02:00
const app = require('./app')(config);
2016-06-18 21:53:18 +02:00
const server = app.listen(app.get('port'), () => {
logger.info(`unleash started on ${app.get('port')}`);
});
return {
2016-06-18 21:53:18 +02:00
app,
server,
2016-06-18 21:55:46 +02:00
config,
};
}
2016-06-18 21:53:18 +02:00
process.on('uncaughtException', err => {
logger.error('Uncaught Exception:', err.message);
logger.error(err.stack);
});
module.exports = {
2016-06-18 21:55:46 +02:00
start,
};