mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-17 14:00:29 +01:00
feat: closes #11630
install & launch forum after entering admin user details in one step
This commit is contained in:
@@ -50,6 +50,9 @@ let installing = false;
|
|||||||
let success = false;
|
let success = false;
|
||||||
let error = false;
|
let error = false;
|
||||||
let launchUrl;
|
let launchUrl;
|
||||||
|
let timeStart = 0;
|
||||||
|
const totalTime = 1000 * 60 * 3;
|
||||||
|
|
||||||
|
|
||||||
const viewsDir = path.join(paths.baseDir, 'build/public/templates');
|
const viewsDir = path.join(paths.baseDir, 'build/public/templates');
|
||||||
|
|
||||||
@@ -102,7 +105,6 @@ function launchExpress(port) {
|
|||||||
function setupRoutes() {
|
function setupRoutes() {
|
||||||
app.get('/', welcome);
|
app.get('/', welcome);
|
||||||
app.post('/', install);
|
app.post('/', install);
|
||||||
app.post('/launch', launch);
|
|
||||||
app.get('/ping', ping);
|
app.get('/ping', ping);
|
||||||
app.get('/sping', ping);
|
app.get('/sping', ping);
|
||||||
}
|
}
|
||||||
@@ -123,7 +125,6 @@ function welcome(req, res) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const defaults = require('./data/defaults.json');
|
const defaults = require('./data/defaults.json');
|
||||||
|
|
||||||
res.render('install/index', {
|
res.render('install/index', {
|
||||||
url: nconf.get('url') || (`${req.protocol}://${req.get('host')}`),
|
url: nconf.get('url') || (`${req.protocol}://${req.get('host')}`),
|
||||||
launchUrl: launchUrl,
|
launchUrl: launchUrl,
|
||||||
@@ -136,6 +137,7 @@ function welcome(req, res) {
|
|||||||
minimumPasswordLength: defaults.minimumPasswordLength,
|
minimumPasswordLength: defaults.minimumPasswordLength,
|
||||||
minimumPasswordStrength: defaults.minimumPasswordStrength,
|
minimumPasswordStrength: defaults.minimumPasswordStrength,
|
||||||
installing: installing,
|
installing: installing,
|
||||||
|
percentInstalled: installing ? ((Date.now() - timeStart) / totalTime * 100).toFixed(2) : 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +145,7 @@ function install(req, res) {
|
|||||||
if (installing) {
|
if (installing) {
|
||||||
return welcome(req, res);
|
return welcome(req, res);
|
||||||
}
|
}
|
||||||
|
timeStart = Date.now();
|
||||||
req.setTimeout(0);
|
req.setTimeout(0);
|
||||||
installing = true;
|
installing = true;
|
||||||
|
|
||||||
@@ -170,21 +173,22 @@ function install(req, res) {
|
|||||||
const child = require('child_process').fork('app', ['--setup'], {
|
const child = require('child_process').fork('app', ['--setup'], {
|
||||||
env: setupEnvVars,
|
env: setupEnvVars,
|
||||||
});
|
});
|
||||||
|
child.on('error', (err) => {
|
||||||
|
error = true;
|
||||||
|
success = false;
|
||||||
|
winston.error(err.stack);
|
||||||
|
});
|
||||||
child.on('close', (data) => {
|
child.on('close', (data) => {
|
||||||
installing = false;
|
|
||||||
success = data === 0;
|
success = data === 0;
|
||||||
error = data !== 0;
|
error = data !== 0;
|
||||||
|
launch();
|
||||||
welcome(req, res);
|
|
||||||
});
|
});
|
||||||
|
welcome(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function launch(req, res) {
|
async function launch() {
|
||||||
try {
|
try {
|
||||||
res.json({});
|
|
||||||
server.close();
|
server.close();
|
||||||
req.setTimeout(0);
|
|
||||||
let child;
|
let child;
|
||||||
|
|
||||||
if (!nconf.get('launchCmd')) {
|
if (!nconf.get('launchCmd')) {
|
||||||
|
|||||||
@@ -21,12 +21,29 @@ $('document').ready(function () {
|
|||||||
}, 400);
|
}, 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) {
|
if ($('#installing').length) {
|
||||||
setTimeout(function () {
|
checkIfReady();
|
||||||
window.location.reload(true);
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupInputs() {
|
function setupInputs() {
|
||||||
@@ -125,21 +142,4 @@ $('document').ready(function () {
|
|||||||
return switchDatabase(field);
|
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,21 +120,17 @@
|
|||||||
{{{ end }}}
|
{{{ end }}}
|
||||||
|
|
||||||
{{{ if installing }}}
|
{{{ if installing }}}
|
||||||
<div id="installing" class="container">
|
<div id="installing" class="container" data-url="{launchUrl}">
|
||||||
<p>
|
<p>
|
||||||
<h1>Hang tight! Your NodeBB is being installed.</h1>
|
<h1>Hang tight! Your NodeBB is being installed.</h1>
|
||||||
</p>
|
</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>
|
</div>
|
||||||
{{{ end }}}
|
{{{ 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">
|
<div class="hide">
|
||||||
{{{ each databases }}}
|
{{{ each databases }}}
|
||||||
<div data-database="{databases.name}">
|
<div data-database="{databases.name}">
|
||||||
|
|||||||
Reference in New Issue
Block a user