1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

Merge pull request #130 from finn-no/injectable-options

make it possible to require server
This commit is contained in:
Ivar Conradi Østhus 2016-06-16 15:50:48 +02:00 committed by GitHub
commit 746c653cc5
3 changed files with 48 additions and 35 deletions

3
index.js Normal file
View File

@ -0,0 +1,3 @@
var server = require('./server');
server.start({});

View File

@ -18,12 +18,13 @@
"engines": { "engines": {
"node": ">=4.4.3" "node": ">=4.4.3"
}, },
"main": "./server.js",
"private": true, "private": true,
"scripts": { "scripts": {
"db-migrate-and-start": "npm run db-migrate && npm run start", "db-migrate-and-start": "npm run db-migrate && npm run start",
"start": "NODE_ENV=production node server.js", "start": "NODE_ENV=production node index.js",
"build": "./node_modules/.bin/webpack -p", "build": "./node_modules/.bin/webpack -p",
"dev": "NODE_ENV=development supervisor --ignore ./node_modules/,./public/js server.js", "dev": "NODE_ENV=development supervisor --ignore ./node_modules/,./public/js index.js",
"start-pg": "pg_virtualenv npm run start-pg-chain", "start-pg": "pg_virtualenv npm run start-pg-chain",
"start-pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run dev", "start-pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run dev",
"test": "export PORT=4243 ; jest && npm run lint && mocha test test/*.js && npm run coverage", "test": "export PORT=4243 ; jest && npm run lint && mocha test test/*.js && npm run coverage",

View File

@ -1,8 +1,11 @@
var logger = require('./lib/logger'); var logger = require('./lib/logger');
var databaseUri = require('./lib/databaseConfig').getDatabaseUrl(); var defaultDatabaseUri = require('./lib/databaseConfig').getDatabaseUrl();
function start(options) {
options = options || {};
var db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
// Database dependecies (statefull) // Database dependecies (statefull)
var db = require('./lib/db/dbPool')(databaseUri);
var eventDb = require('./lib/db/event')(db); var eventDb = require('./lib/db/event')(db);
var EventStore = require('./lib/eventStore'); var EventStore = require('./lib/eventStore');
var eventStore = new EventStore(eventDb); var eventStore = new EventStore(eventDb);
@ -19,6 +22,7 @@ var config = {
strategyDb: strategyDb strategyDb: strategyDb
}; };
var app = require('./app')(config); var app = require('./app')(config);
var server = app.listen(app.get('port'), function() { var server = app.listen(app.get('port'), function() {
@ -39,12 +43,17 @@ if (app.get('env') === 'development') {
})); }));
} }
return {
app: app,
server: server
};
}
process.on('uncaughtException', function(err) { process.on('uncaughtException', function(err) {
logger.error('Uncaught Exception:', err.message); logger.error('Uncaught Exception:', err.message);
logger.error(err.stack); logger.error(err.stack);
}); });
module.exports = { module.exports = {
app: app, start: start
server: server
}; };