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

Merge branch 'master' of github.com:finn-no/unleash

This commit is contained in:
Ivar 2016-09-29 23:08:41 +02:00
commit 5d10c939c8
5 changed files with 80 additions and 18 deletions

View File

@ -0,0 +1,25 @@
'use strict';
const DBMigrate = require('db-migrate');
const path = require('path');
function findUnleashApiRoot () {
try {
return path.dirname(require.resolve('unleash-api/package.json'));
} catch (e) {}
try {
return path.dirname(require.resolve('../unleash-api/package.json'));
} catch (e) {}
return process.cwd();
}
function migrateDb (dbUri) {
const dbmigrate = DBMigrate.getInstance(true, {
cwd: findUnleashApiRoot(),
config: { custom: dbUri },
env: 'custom' }
);
return dbmigrate.up();
}
module.exports = migrateDb;

View File

@ -36,6 +36,7 @@
"start:dev:pg": "pg_virtualenv npm run start:dev:pg-chain",
"start:dev:pg-chain": "export DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@localhost:$PGPORT/postgres ; db-migrate up && npm run start:dev",
"db-migrate": "db-migrate up",
"db-migrate:down": "db-migrate down",
"test": "export PORT=4243 ; mocha test/**/*.js && npm run test:coverage",
"test:unit": "mocha test/unit/**/*.js ",
"test:ci": "npm run db-migrate && npm run test",
@ -49,7 +50,8 @@
"bluebird": "^3.4.6",
"body-parser": "1.15.2",
"cookie-parser": "^1.4.1",
"db-migrate": "0.9.25",
"db-migrate": "0.10.0-beta.17",
"db-migrate-pg": "0.1.10",
"deep-diff": "^0.3.3",
"errorhandler": "^1.4.3",
"express": "4.14.0",

View File

@ -1,11 +1,16 @@
'use strict';
const logger = require('./lib/logger');
const defaultDatabaseUri = process.env.DATABASE_URL;
const migrator = require('./migrator');
function start (options) {
options = options || {};
const DEFAULT_OPTIONS = {
databaseUri: process.env.DATABASE_URL,
port: process.env.HTTP_PORT || process.env.PORT || 4242,
baseUriPath: process.env.BASE_URI_PATH || '',
};
function createApp (options) {
const db = require('./lib/db/dbPool')(options.databaseUri);
const db = require('./lib/db/dbPool')(options.databaseUri || defaultDatabaseUri);
// Database dependecies (statefull)
const eventDb = require('./lib/db/event')(db);
const EventStore = require('./lib/eventStore');
@ -14,27 +19,33 @@ function start (options) {
const strategyDb = require('./lib/db/strategy')(db, eventStore);
const config = {
baseUriPath: process.env.BASE_URI_PATH || '',
port: process.env.HTTP_PORT || process.env.PORT || 4242,
baseUriPath: options.baseUriPath,
port: options.port,
publicFolder: options.publicFolder,
db,
eventDb,
eventStore,
featureDb,
strategyDb,
publicFolder: options.publicFolder,
};
const app = require('./app')(config);
const server = app.listen(app.get('port'), () => {
logger.info(`unleash started on ${app.get('port')}`);
logger.info(`Unleash started on ${app.get('port')}`);
});
return { app, server };
}
return {
app,
server,
config,
};
function start (opts) {
const options = Object.assign({}, DEFAULT_OPTIONS, opts);
if (!options.databaseUri) {
throw new Error('You must either pass databaseUri option or set environemnt variable DATABASE_URL');
}
return migrator(options.databaseUri)
.then(() => createApp(options))
.catch(err => logger.error('failed to migrate db', err));
}
process.on('uncaughtException', err => {

View File

@ -0,0 +1,22 @@
#!/usr/bin/env node
'use strict';
process.env.NODE_ENV = 'production';
const program = require('commander');
const unleash = require('../server.js');
program
.option('-p, --port <port>', 'The port you want to start unleash on')
.option('-d, --databaseUri <databaseUri>', 'The full databaseUri to connect to, including username and password')
.parse(process.argv);
unleash.start({
databaseUri: program.databaseUri || process.env.DATABASE_URL,
port: program.port || process.env.PORT || 4242,
}).then(conf => {
console.log(`Unleash started on port:${conf.app.get('port')}`);
});

View File

@ -24,6 +24,9 @@
"node": "6"
},
"main": "./server.js",
"bin": {
"unleash": "./bin/unleash.js"
},
"scripts": {
"db-migrate-and-start": "npm run db-migrate && npm run start",
"start": "NODE_ENV=production node server-impl.js",
@ -31,10 +34,9 @@
"test:ci": "npm run test"
},
"dependencies": {
"commander": "^2.9.0",
"unleash-api": "1.0.0-alpha.2",
"unleash-frontend": "1.0.0-alpha.2"
},
"devDependencies": {
}
"devDependencies": {}
}