diff --git a/bin/unleash.js b/bin/unleash.js index 65d1a669c0..3935e1ba9b 100755 --- a/bin/unleash.js +++ b/bin/unleash.js @@ -3,20 +3,24 @@ process.env.NODE_ENV = 'production'; -const { publicFolder } = require('unleash-frontend'); const program = require('commander'); -const unleash = require('../lib/server-impl.js'); +const { createOptions } = require('../lib/options.js'); +const serverImpl = require('../lib/server-impl.js'); program .option('-p, --port ', 'The port you want to start unleash on') .option('-d, --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, - publicFolder, -}).then(conf => { - console.log(`Unleash started on port:${conf.app.get('port')}`); -}); +const userOpts = {}; +if(program.databaseUri) { + userOpts.databaseUri = program.databaseUri; +} +if(program.port) { + userOpts.port = program.port; +} + +serverImpl.start(createOptions(userOpts)) + .then(conf => console.log(`Unleash started on http://localhost:${conf.app.get('port')}`)) + .catch(console.err); diff --git a/lib/options.js b/lib/options.js index ff5a46a007..3abd347f46 100644 --- a/lib/options.js +++ b/lib/options.js @@ -1,10 +1,12 @@ 'use strict'; +const { publicFolder } = require('unleash-frontend'); const DEFAULT_OPTIONS = { databaseUri: process.env.DATABASE_URL, port: process.env.HTTP_PORT || process.env.PORT || 4242, baseUriPath: process.env.BASE_URI_PATH || '', serverMetrics: true, + publicFolder, }; module.exports = { diff --git a/server.js b/server.js index 800c35b283..28c7c0cb2a 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,5 @@ 'use strict'; const unleash = require('./lib/server-impl'); -const { publicFolder } = require('unleash-frontend'); -unleash.start({ publicFolder }); +unleash.start();