mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
Merge pull request #130 from finn-no/injectable-options
make it possible to require server
This commit is contained in:
commit
746c653cc5
@ -18,12 +18,13 @@
|
||||
"engines": {
|
||||
"node": ">=4.4.3"
|
||||
},
|
||||
"main": "./server.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"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",
|
||||
"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-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",
|
||||
|
75
server.js
75
server.js
@ -1,42 +1,52 @@
|
||||
var logger = require('./lib/logger');
|
||||
var databaseUri = require('./lib/databaseConfig').getDatabaseUrl();
|
||||
var defaultDatabaseUri = require('./lib/databaseConfig').getDatabaseUrl();
|
||||
|
||||
// Database dependecies (statefull)
|
||||
var db = require('./lib/db/dbPool')(databaseUri);
|
||||
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);
|
||||
function start(options) {
|
||||
options = options || {};
|
||||
|
||||
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 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 app = require('./app')(config);
|
||||
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 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 app = require('./app')(config);
|
||||
|
||||
var webpack = require('webpack');
|
||||
var webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
var webpackConfig = require('./webpack.config');
|
||||
var compiler = webpack(webpackConfig);
|
||||
var server = app.listen(app.get('port'), function() {
|
||||
logger.info('unleash started on ' + app.get('port'));
|
||||
});
|
||||
|
||||
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
|
||||
publicPath: '/js',
|
||||
noInfo: true
|
||||
}));
|
||||
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) {
|
||||
@ -45,6 +55,5 @@ process.on('uncaughtException', function(err) {
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
app: app,
|
||||
server: server
|
||||
start: start
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user