Skip to content

Node.js based forum software built for the modern web

feat: closes #11630

Barış Soner Uşaklı8c9ab01f3f13
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 }}}
- <div id="installing" class="container">
+ <div id="installing" class="container" data-url="{launchUrl}">
<p>
<h1>Hang tight! Your NodeBB is being installed.</h1>
</p>
+ <p class="lead">This might take a few minutes, you will be redirected once your forum is ready.</p>
+ <div class="progress" style="height: 20px;">
+ <div class="progress-bar" role="progressbar" data-percent="{percentInstalled}" style="width: {percentInstalled}%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
+ </div>
</div>
{{{ end }}}
- <div class="container {{{ if !success }}}hide{{{ end }}}">
- <p>
- <h1>Congratulations! Your NodeBB has been set-up.</h1>
-
- <button id="launch" data-url="{launchUrl}" class="btn btn btn-success">Launch NodeBB <i class="working hide"></i></button>
- </p>
- </div>
-
<div class="hide">
{{{ each databases }}}
<div data-database="{databases.name}">