write placeholder page when webserver is first starting

This commit is contained in:
Michael Bradley, Jr 2018-08-31 11:06:46 -05:00
parent b47435cc45
commit f778dad589
1 changed files with 12 additions and 0 deletions

View File

@ -1,9 +1,15 @@
let finalhandler = require('finalhandler'); let finalhandler = require('finalhandler');
const fs = require('../../core/fs.js');
let http = require('http'); let http = require('http');
let serveStatic = require('serve-static'); let serveStatic = require('serve-static');
const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host'); const {canonicalHost, defaultHost, dockerHostSwap} = require('../../utils/host');
const utils = require('../../utils/utils.js');
require('http-shutdown').extend(); require('http-shutdown').extend();
require('ejs');
const embark_building_placeholder = require('../code_generator/code_templates/embark-building-placeholder.html.ejs');
let isFirstStart = true;
class Server { class Server {
constructor(options) { constructor(options) {
this.dist = options.dist || 'dist/'; this.dist = options.dist || 'dist/';
@ -24,6 +30,12 @@ class Server {
serve(req, res, finalhandler(req, res)); serve(req, res, finalhandler(req, res));
}).withShutdown(); }).withShutdown();
if (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.server.listen(this.port, this.hostname, () => { this.server.listen(this.port, this.hostname, () => {
this.port = this.server.address().port; this.port = this.server.address().port;