diff --git a/install/web.js b/install/web.js index dd908679cf..a4409079b5 100644 --- a/install/web.js +++ b/install/web.js @@ -50,6 +50,9 @@ let installing = false; let success = false; let error = false; let launchUrl; +let timeStart = 0; +const totalTime = 1000 * 60 * 3; + const viewsDir = path.join(paths.baseDir, 'build/public/templates'); @@ -102,7 +105,6 @@ function launchExpress(port) { function setupRoutes() { app.get('/', welcome); app.post('/', install); - app.post('/launch', launch); app.get('/ping', ping); app.get('/sping', ping); } @@ -123,7 +125,6 @@ function welcome(req, res) { }); const defaults = require('./data/defaults.json'); - res.render('install/index', { url: nconf.get('url') || (`${req.protocol}://${req.get('host')}`), launchUrl: launchUrl, @@ -136,6 +137,7 @@ function welcome(req, res) { minimumPasswordLength: defaults.minimumPasswordLength, minimumPasswordStrength: defaults.minimumPasswordStrength, installing: installing, + percentInstalled: installing ? ((Date.now() - timeStart) / totalTime * 100).toFixed(2) : 0, }); } @@ -143,6 +145,7 @@ function install(req, res) { if (installing) { return welcome(req, res); } + timeStart = Date.now(); req.setTimeout(0); installing = true; @@ -170,21 +173,22 @@ function install(req, res) { const child = require('child_process').fork('app', ['--setup'], { env: setupEnvVars, }); - + child.on('error', (err) => { + error = true; + success = false; + winston.error(err.stack); + }); child.on('close', (data) => { - installing = false; success = data === 0; error = data !== 0; - - welcome(req, res); + launch(); }); + welcome(req, res); } -async function launch(req, res) { +async function launch() { try { - res.json({}); server.close(); - req.setTimeout(0); let child; if (!nconf.get('launchCmd')) { diff --git a/public/src/installer/install.js b/public/src/installer/install.js index b18743f39f..16a826710c 100644 --- a/public/src/installer/install.js +++ b/public/src/installer/install.js @@ -21,12 +21,29 @@ $('document').ready(function () { }, 400); } - $('#launch').on('click', launchForum); + function checkIfReady() { + let successCount = 0; + const url = $('#installing').attr('data-url'); + const progressEl = $('#installing .progress-bar'); + const intervalId = setInterval(function () { + let p = parseFloat(progressEl.attr('data-percent'), 10) || 0; + p = Math.min(100, p + 1.5); + progressEl.attr('data-percent', p); + progressEl.css({ width: p + '%' }); + + $.get(url + '/admin').done(function () { + if (successCount >= 5) { + window.location = url + '/admin'; + clearInterval(intervalId); + } else { + successCount += 1; + } + }); + }, 2500); + } if ($('#installing').length) { - setTimeout(function () { - window.location.reload(true); - }, 5000); + checkIfReady(); } function setupInputs() { @@ -125,21 +142,4 @@ $('document').ready(function () { return switchDatabase(field); } } - - function launchForum() { - $('#launch .working').removeClass('hide'); - $.post('/launch', function () { - let successCount = 0; - const url = $('#launch').attr('data-url'); - setInterval(function () { - $.get(url + '/admin').done(function () { - if (successCount >= 5) { - window.location = 'admin'; - } else { - successCount += 1; - } - }); - }, 750); - }); - } }); diff --git a/src/views/install/index.tpl b/src/views/install/index.tpl index 61f9e6785c..bc8a60abd2 100644 --- a/src/views/install/index.tpl +++ b/src/views/install/index.tpl @@ -120,21 +120,17 @@ {{{ end }}} {{{ if installing }}} -
+

Hang tight! Your NodeBB is being installed.

+

This might take a few minutes, you will be redirected once your forum is ready.

+
+
+
{{{ end }}} -
-

-

Congratulations! Your NodeBB has been set-up.

- - -

-
-
{{{ each databases }}}