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": {
|
"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",
|
||||||
|
75
server.js
75
server.js
@ -1,42 +1,52 @@
|
|||||||
var logger = require('./lib/logger');
|
var logger = require('./lib/logger');
|
||||||
var databaseUri = require('./lib/databaseConfig').getDatabaseUrl();
|
var defaultDatabaseUri = require('./lib/databaseConfig').getDatabaseUrl();
|
||||||
|
|
||||||
// Database dependecies (statefull)
|
function start(options) {
|
||||||
var db = require('./lib/db/dbPool')(databaseUri);
|
options = options || {};
|
||||||
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 = {
|
var db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
|
||||||
baseUriPath: process.env.BASE_URI_PATH || '',
|
// Database dependecies (statefull)
|
||||||
port: process.env.HTTP_PORT || process.env.PORT || 4242,
|
var eventDb = require('./lib/db/event')(db);
|
||||||
db: db,
|
var EventStore = require('./lib/eventStore');
|
||||||
eventDb: eventDb,
|
var eventStore = new EventStore(eventDb);
|
||||||
eventStore: eventStore,
|
var featureDb = require('./lib/db/feature')(db, eventStore);
|
||||||
featureDb: featureDb,
|
var strategyDb = require('./lib/db/strategy')(db, eventStore);
|
||||||
strategyDb: strategyDb
|
|
||||||
};
|
|
||||||
|
|
||||||
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') {
|
var app = require('./app')(config);
|
||||||
app.use(require('errorhandler')());
|
|
||||||
|
|
||||||
var webpack = require('webpack');
|
var server = app.listen(app.get('port'), function() {
|
||||||
var webpackDevMiddleware = require('webpack-dev-middleware');
|
logger.info('unleash started on ' + app.get('port'));
|
||||||
var webpackConfig = require('./webpack.config');
|
});
|
||||||
var compiler = webpack(webpackConfig);
|
|
||||||
|
|
||||||
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
|
if (app.get('env') === 'development') {
|
||||||
publicPath: '/js',
|
app.use(require('errorhandler')());
|
||||||
noInfo: true
|
|
||||||
}));
|
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) {
|
process.on('uncaughtException', function(err) {
|
||||||
@ -45,6 +55,5 @@ process.on('uncaughtException', function(err) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
app: app,
|
start: start
|
||||||
server: server
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user