From 1d9237820adad40fe746f7e9382472479e54ff3e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 31 Aug 2018 11:46:41 -0500 Subject: [PATCH] make isFirstStart, opened props of Server instance --- lib/modules/webserver/server.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 361e67ec9..9c3e90592 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -10,14 +10,13 @@ require('http-shutdown').extend(); require('ejs'); const embark_building_placeholder = require('../code_generator/code_templates/embark-building-placeholder.html.ejs'); -let isFirstStart = true; -let opened = false; - class Server { constructor(options) { this.dist = options.dist || 'dist/'; this.port = options.port || 8000; this.hostname = dockerHostSwap(options.host) || defaultHost; + this.isFirstStart = true; + this.opened = false; } start(callback) { @@ -33,11 +32,11 @@ class Server { serve(req, res, finalhandler(req, res)); }).withShutdown(); - if (isFirstStart) { + if (this.isFirstStart) { const html = embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')}); fs.mkdirpSync(this.dist); // create dist/ folder if not already exists fs.writeFileSync(utils.joinPath(this.dist, 'index.html'), html); - isFirstStart = false; + this.isFirstStart = false; } this.server.listen(this.port, this.hostname, () => { @@ -46,12 +45,12 @@ class Server { " " + ("http://" + canonicalHost(this.hostname) + ":" + this.port).bold.underline.green, this.port); - if (!opened) { + if (!this.opened) { // fail silently, e.g. in a docker container, by cacthing promise // rejection w/ a noop opn(`http://${canonicalHost(this.hostname)}:${this.port}`) .catch(function () {}); - opened = true; + this.opened = true; } }); }