diff --git a/bin/unleash.js b/bin/unleash.js index 44c491c643..65d1a669c0 100755 --- a/bin/unleash.js +++ b/bin/unleash.js @@ -5,7 +5,7 @@ process.env.NODE_ENV = 'production'; const { publicFolder } = require('unleash-frontend'); const program = require('commander'); -const unleash = require('../server-impl.js'); +const unleash = require('../lib/server-impl.js'); program .option('-p, --port ', 'The port you want to start unleash on') @@ -15,7 +15,7 @@ program unleash.start({ databaseUri: program.databaseUri || process.env.DATABASE_URL, port: program.port || process.env.PORT || 4242, - publicFolder + publicFolder, }).then(conf => { console.log(`Unleash started on port:${conf.app.get('port')}`); }); diff --git a/app.js b/lib/app.js similarity index 95% rename from app.js rename to lib/app.js index 3012293841..937f8046bc 100644 --- a/app.js +++ b/lib/app.js @@ -6,8 +6,8 @@ const bodyParser = require('body-parser'); const cookieParser = require('cookie-parser'); const validator = require('express-validator'); const log4js = require('log4js'); -const logger = require('./lib/logger'); -const routes = require('./lib/routes'); +const logger = require('./logger'); +const routes = require('./routes'); const path = require('path'); const errorHandler = require('errorhandler'); diff --git a/server-impl.js b/lib/server-impl.js similarity index 89% rename from server-impl.js rename to lib/server-impl.js index 5676771da2..7696d11ffb 100644 --- a/server-impl.js +++ b/lib/server-impl.js @@ -1,9 +1,9 @@ 'use strict'; -const logger = require('./lib/logger'); -const migrator = require('./migrator'); -const { createStores } = require('./lib/db'); -const getApp = require('./app'); +const logger = require('./logger'); +const migrator = require('../migrator'); +const { createStores } = require('./db'); +const getApp = require('./lib/app'); const DEFAULT_OPTIONS = { databaseUri: process.env.DATABASE_URL || 'postgres://unleash_user:passord@localhost:5432/unleash', diff --git a/package.json b/package.json index 1264140dad..d104705c0b 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "unleash": "./bin/unleash.js" }, "scripts": { - "start": "node server-dev.js", - "start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ server-dev.js", + "start": "node server.js", + "start:dev": "NODE_ENV=development supervisor --ignore ./node_modules/ server.js", "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", diff --git a/server-dev.js b/server.js similarity index 69% rename from server-dev.js rename to server.js index b93deff36f..800c35b283 100644 --- a/server-dev.js +++ b/server.js @@ -1,6 +1,6 @@ 'use strict'; -const unleash = require('./server-impl'); +const unleash = require('./lib/server-impl'); const { publicFolder } = require('unleash-frontend'); unleash.start({ publicFolder }); diff --git a/test/e2e/helpers/test-helper.js b/test/e2e/helpers/test-helper.js index d82d1ca495..1f112c36ee 100644 --- a/test/e2e/helpers/test-helper.js +++ b/test/e2e/helpers/test-helper.js @@ -6,7 +6,7 @@ const supertest = require('supertest'); const migrator = require('../../../migrator'); const { createStores } = require('../../../lib/db'); const { createDb } = require('../../../lib/db/db-pool'); -const _app = require('../../../app'); +const getApp = require('../../../lib/app'); require('db-migrate-shared').log.silence(true); // because of migrator bug @@ -26,7 +26,7 @@ function createApp (databaseSchema = 'test') { .then(() => { db.destroy(); const stores = createStores(options); - const app = _app({ stores }); + const app = getApp({ stores }); return { stores, request: supertest(app), diff --git a/test/unit/routes/feature.test.js b/test/unit/routes/feature.test.js index 275c0ef8cb..23d055eefa 100644 --- a/test/unit/routes/feature.test.js +++ b/test/unit/routes/feature.test.js @@ -4,6 +4,7 @@ const test = require('ava'); const store = require('./fixtures/store'); const supertest = require('supertest'); const logger = require('../../../lib/logger'); +const getApp = require('../../../lib/app'); test.beforeEach(() => { logger.setLevel('FATAL'); @@ -12,7 +13,7 @@ test.beforeEach(() => { function getSetup () { const base = `/random${Math.round(Math.random() * 1000)}`; const stores = store.createStores(); - const app = require('../../../app')({ + const app = getApp({ baseUriPath: base, stores, }); diff --git a/test/unit/routes/health-check.test.js b/test/unit/routes/health-check.test.js index 793bbf2fe2..e40481ce15 100644 --- a/test/unit/routes/health-check.test.js +++ b/test/unit/routes/health-check.test.js @@ -4,6 +4,7 @@ const test = require('ava'); const store = require('./fixtures/store'); const supertest = require('supertest'); const logger = require('../../../lib/logger'); +const getApp = require('../../../lib/app'); test.beforeEach(() => { logger.setLevel('FATAL'); @@ -13,7 +14,7 @@ test.beforeEach(() => { function getSetup () { const stores = store.createStores(); const db = stores.db; - const app = require('../../../app')({ + const app = getApp({ baseUriPath: '', stores, }); diff --git a/test/unit/routes/metrics.test.js b/test/unit/routes/metrics.test.js index 3466bf2292..39e67a9222 100644 --- a/test/unit/routes/metrics.test.js +++ b/test/unit/routes/metrics.test.js @@ -4,6 +4,7 @@ const test = require('ava'); const store = require('./fixtures/store'); const supertest = require('supertest'); const logger = require('../../../lib/logger'); +const getApp = require('../../../lib/app'); test.beforeEach(() => { logger.setLevel('FATAL'); @@ -11,7 +12,7 @@ test.beforeEach(() => { function getSetup () { const stores = store.createStores(); - const app = require('../../../app')({ + const app = getApp({ baseUriPath: '', stores, }); diff --git a/test/unit/routes/strategies.test.js b/test/unit/routes/strategies.test.js index a7e2360dcb..14bc29ad2e 100644 --- a/test/unit/routes/strategies.test.js +++ b/test/unit/routes/strategies.test.js @@ -4,6 +4,7 @@ const test = require('ava'); const store = require('./fixtures/store'); const supertest = require('supertest'); const logger = require('../../../lib/logger'); +const getApp = require('../../../lib/app'); test.beforeEach(() => { logger.setLevel('FATAL'); @@ -11,7 +12,7 @@ test.beforeEach(() => { test('should add version numbers for /stategies', t => { const stores = store.createStores(); - const app = require('../../../app')({ + const app = getApp({ baseUriPath: '', stores, });