From da39a3065f45373ae12a0f4b136486ee87cc1a50 Mon Sep 17 00:00:00 2001 From: brunosimon Date: Sun, 24 Dec 2017 13:06:04 +0100 Subject: [PATCH] :bug: Fix browser not opening when using --host parameter --- lib/chat.js | 2 +- lib/index.js | 64 ++++++++++++++++++++++++++++++++++++---------------- readme.md | 2 +- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/lib/chat.js b/lib/chat.js index babe7cf..790f653 100644 --- a/lib/chat.js +++ b/lib/chat.js @@ -26,7 +26,7 @@ class Chat setSocket() { - // Create a channel for this specific chjat + // Create a channel for this specific chat this.chatSocket = this.config.socket.of('/project/' + this.slug + '/chat') // Connection event diff --git a/lib/index.js b/lib/index.js index 70df752..bc263a2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,21 +28,16 @@ class App this.setConfig() // If host is not specified - // Start the site + // Start the server if(!this.config.host) { - this.setSite( - () => - { - this.setSocket() - this.setProjects() - }, - () => - { - console.log('error'.red) - console.log('app'.green.bold + ' - ' + 'keppler seems to be running already'.cyan) - } - ) + this.setServer() + } + + // If host is specified, show URL open in browser + if(this.config.host) + { + this.showUrlAndOpen() } // If not started as a server @@ -175,6 +170,26 @@ class App } } + /** + * Set server + * Insitantiate the site and when the site is ready, instantiate the socket connexion and projects + */ + setServer() + { + this.setSite( + () => + { + this.setSocket() + this.setProjects() + }, + () => + { + console.log('error'.red) + console.log('app'.green.bold + ' - ' + 'keppler seems to be running already'.cyan) + } + ) + } + /** * Set site * Instantiate site @@ -224,13 +239,10 @@ class App console.log(util.inspect(project.files.describe(), { depth: null, colors: true })) } - // Open in browser - const url = this.config.domain - console.log('app'.green.bold + ' - ' + url.yellow) - - if(this.config.open) + // If not server, show URL open in browser + if(!this.config.server) { - opener(url) + this.showUrlAndOpen() } }) @@ -315,6 +327,20 @@ class App { this.watcher = new Watcher(this.config) } + + /** + * Show URL and open it if should + */ + showUrlAndOpen() + { + const url = this.config.domain + console.log('app'.green.bold + ' - ' + url.yellow) + + if(this.config.open) + { + opener(url) + } + } } module.exports = App diff --git a/readme.md b/readme.md index c511f0d..1d98a0b 100644 --- a/readme.md +++ b/readme.md @@ -114,7 +114,7 @@ Arguments list |parameter|`--server`| |shortcut|`-s`| |default value|*(bool)*`false`| -|description|Start keppler has a server
(if you want to run an online instance)| +|description|Start keppler server only
(if you want to run an online instance)| ||| |---|---|