From 35ad3aa072ea38c596bae47e14f03bb0bf2ac11a Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Fri, 2 Dec 2016 16:34:05 +0100 Subject: [PATCH] cleanup bin --- bin/unleash.js | 22 +++++++++++++--------- lib/options.js | 2 ++ server.js | 3 +-- 3 files changed, 16 insertions(+), 11 deletions(-) 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();