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

Fixed api from server-impl to make it easier to require.

only release resources needed by others.
This commit is contained in:
Ivar 2016-06-16 17:27:13 +02:00 committed by Ivar Conradi Østhus
parent 1bbe65a398
commit a05cea474d
5 changed files with 77 additions and 65 deletions

View File

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

View File

@ -8,6 +8,16 @@
"feature",
"toggle"
],
"files": [
"lib",
"migrations",
"public",
"app.js",
"server.js",
"server-impl.js",
"README.md",
"LICENSE"
],
"repository": {
"type": "git",
"url": "ssh://git@github.com:finn-no/unleash.git"
@ -18,13 +28,13 @@
"engines": {
"node": ">=4.4.3"
},
"main": "./server.js",
"main": "./server-impl.js",
"private": true,
"scripts": {
"db-migrate-and-start": "npm run db-migrate && npm run start",
"start": "NODE_ENV=production node index.js",
"start": "npm run build && NODE_ENV=production node server.js",
"build": "./node_modules/.bin/webpack -p",
"dev": "NODE_ENV=development supervisor --ignore ./node_modules/,./public/js index.js",
"dev": "NODE_ENV=development supervisor --ignore ./node_modules/,./public/js server-dev.js",
"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",
"test": "export PORT=4243 ; jest && npm run lint && mocha test test/*.js && npm run coverage",
@ -37,7 +47,6 @@
"test-bamboo-ci": "mocha test test/*",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec",
"coverage-report": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"postinstall": "npm run build",
"jest": "jest",
"lint": "eslint . --ignore-path .gitignore"
},

17
server-dev.js Normal file
View File

@ -0,0 +1,17 @@
var server = require('./server-impl');
var unleash = server.start({});
var app = unleash.app;
var config = unleash.config;
app.use(require('errorhandler')());
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackConfig = require('./webpack.config');
var compiler = webpack(webpackConfig);
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
publicPath: '/js',
noInfo: true
}));

45
server-impl.js Normal file
View File

@ -0,0 +1,45 @@
var logger = require('./lib/logger');
var defaultDatabaseUri = require('./lib/databaseConfig').getDatabaseUrl();
function start(options) {
options = options || {};
var db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
// Database dependecies (statefull)
var eventDb = require('./lib/db/event')(db);
var EventStore = require('./lib/eventStore');
var eventStore = new EventStore(eventDb);
var featureDb = require('./lib/db/feature')(db, eventStore);
var strategyDb = require('./lib/db/strategy')(db, eventStore);
var config = {
baseUriPath: process.env.BASE_URI_PATH || '',
port: process.env.HTTP_PORT || process.env.PORT || 4242,
db: db,
eventDb: eventDb,
eventStore: eventStore,
featureDb: featureDb,
strategyDb: strategyDb
};
var app = require('./app')(config);
var server = app.listen(app.get('port'), function() {
logger.info('unleash started on ' + app.get('port'));
});
return {
app: app,
server: server,
config: config
};
}
process.on('uncaughtException', function(err) {
logger.error('Uncaught Exception:', err.message);
logger.error(err.stack);
});
module.exports = {
start: start
};

View File

@ -1,59 +1,3 @@
var logger = require('./lib/logger');
var defaultDatabaseUri = require('./lib/databaseConfig').getDatabaseUrl();
var server = require('./server-impl');
function start(options) {
options = options || {};
var db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
// Database dependecies (statefull)
var eventDb = require('./lib/db/event')(db);
var EventStore = require('./lib/eventStore');
var eventStore = new EventStore(eventDb);
var featureDb = require('./lib/db/feature')(db, eventStore);
var strategyDb = require('./lib/db/strategy')(db, eventStore);
var config = {
baseUriPath: process.env.BASE_URI_PATH || '',
port: process.env.HTTP_PORT || process.env.PORT || 4242,
db: db,
eventDb: eventDb,
eventStore: eventStore,
featureDb: featureDb,
strategyDb: strategyDb
};
var app = require('./app')(config);
var server = app.listen(app.get('port'), function() {
logger.info('unleash started on ' + app.get('port'));
});
if (app.get('env') === 'development') {
app.use(require('errorhandler')());
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackConfig = require('./webpack.config');
var compiler = webpack(webpackConfig);
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
publicPath: '/js',
noInfo: true
}));
}
return {
app: app,
server: server
};
}
process.on('uncaughtException', function(err) {
logger.error('Uncaught Exception:', err.message);
logger.error(err.stack);
});
module.exports = {
start: start
};
server.start({});