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:
commit
5d10c939c8
25
packages/unleash-api/migrator.js
Normal file
25
packages/unleash-api/migrator.js
Normal 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;
|
@ -36,6 +36,7 @@
|
|||||||
"start:dev:pg": "pg_virtualenv npm run start:dev:pg-chain",
|
"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",
|
"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": "db-migrate up",
|
||||||
|
"db-migrate:down": "db-migrate down",
|
||||||
"test": "export PORT=4243 ; mocha test/**/*.js && npm run test:coverage",
|
"test": "export PORT=4243 ; mocha test/**/*.js && npm run test:coverage",
|
||||||
"test:unit": "mocha test/unit/**/*.js ",
|
"test:unit": "mocha test/unit/**/*.js ",
|
||||||
"test:ci": "npm run db-migrate && npm run test",
|
"test:ci": "npm run db-migrate && npm run test",
|
||||||
@ -49,7 +50,8 @@
|
|||||||
"bluebird": "^3.4.6",
|
"bluebird": "^3.4.6",
|
||||||
"body-parser": "1.15.2",
|
"body-parser": "1.15.2",
|
||||||
"cookie-parser": "^1.4.1",
|
"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",
|
"deep-diff": "^0.3.3",
|
||||||
"errorhandler": "^1.4.3",
|
"errorhandler": "^1.4.3",
|
||||||
"express": "4.14.0",
|
"express": "4.14.0",
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
const logger = require('./lib/logger');
|
const logger = require('./lib/logger');
|
||||||
const defaultDatabaseUri = process.env.DATABASE_URL;
|
const migrator = require('./migrator');
|
||||||
|
|
||||||
function start (options) {
|
const DEFAULT_OPTIONS = {
|
||||||
options = 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)
|
// Database dependecies (statefull)
|
||||||
const eventDb = require('./lib/db/event')(db);
|
const eventDb = require('./lib/db/event')(db);
|
||||||
const EventStore = require('./lib/eventStore');
|
const EventStore = require('./lib/eventStore');
|
||||||
@ -14,27 +19,33 @@ function start (options) {
|
|||||||
const strategyDb = require('./lib/db/strategy')(db, eventStore);
|
const strategyDb = require('./lib/db/strategy')(db, eventStore);
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
baseUriPath: process.env.BASE_URI_PATH || '',
|
baseUriPath: options.baseUriPath,
|
||||||
port: process.env.HTTP_PORT || process.env.PORT || 4242,
|
port: options.port,
|
||||||
|
publicFolder: options.publicFolder,
|
||||||
db,
|
db,
|
||||||
eventDb,
|
eventDb,
|
||||||
eventStore,
|
eventStore,
|
||||||
featureDb,
|
featureDb,
|
||||||
strategyDb,
|
strategyDb,
|
||||||
publicFolder: options.publicFolder,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const app = require('./app')(config);
|
const app = require('./app')(config);
|
||||||
|
|
||||||
const server = app.listen(app.get('port'), () => {
|
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 {
|
function start (opts) {
|
||||||
app,
|
const options = Object.assign({}, DEFAULT_OPTIONS, opts);
|
||||||
server,
|
|
||||||
config,
|
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 => {
|
process.on('uncaughtException', err => {
|
||||||
|
22
packages/unleash-server/bin/unleash.js
Executable file
22
packages/unleash-server/bin/unleash.js
Executable 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')}`);
|
||||||
|
});
|
||||||
|
|
@ -24,6 +24,9 @@
|
|||||||
"node": "6"
|
"node": "6"
|
||||||
},
|
},
|
||||||
"main": "./server.js",
|
"main": "./server.js",
|
||||||
|
"bin": {
|
||||||
|
"unleash": "./bin/unleash.js"
|
||||||
|
},
|
||||||
"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-impl.js",
|
"start": "NODE_ENV=production node server-impl.js",
|
||||||
@ -31,10 +34,9 @@
|
|||||||
"test:ci": "npm run test"
|
"test:ci": "npm run test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"commander": "^2.9.0",
|
||||||
"unleash-api": "1.0.0-alpha.2",
|
"unleash-api": "1.0.0-alpha.2",
|
||||||
"unleash-frontend": "1.0.0-alpha.2"
|
"unleash-frontend": "1.0.0-alpha.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user