From 943d33ed09f3f61b889c64d2d2e1e601427ec407 Mon Sep 17 00:00:00 2001
From: Julian Lam
Date: Tue, 15 May 2018 15:25:59 -0400
Subject: [PATCH] closes #6502, also fixed issue with type: 'literal' in
config.json
---
install/web.js | 2 ++
src/install.js | 22 ++++++++++++++++++----
src/views/install/index.tpl | 16 ++++++++++++++++
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/install/web.js b/install/web.js
index 792dfc6aee..ea24d25fb2 100644
--- a/install/web.js
+++ b/install/web.js
@@ -99,6 +99,8 @@ function welcome(req, res) {
var defaults = require('./data/defaults');
res.render('install/index', {
+ url: nconf.get('url') || (req.protocol + '://' + req.get('host')),
+ skipGeneralSetup: !!nconf.get('url'),
databases: databases,
skipDatabaseSetup: !!nconf.get('database'),
error: !!res.locals.error,
diff --git a/src/install.js b/src/install.js
index 8534ef6529..90db5dd861 100644
--- a/src/install.js
+++ b/src/install.js
@@ -2,6 +2,7 @@
var async = require('async');
var fs = require('fs');
+var url = require('url');
var path = require('path');
var prompt = require('prompt');
var winston = require('winston');
@@ -16,9 +17,7 @@ questions.main = [
name: 'url',
description: 'URL used to access this NodeBB',
default:
- nconf.get('url') ||
- (nconf.get('base_url') ? (nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '')) : null) || // backwards compatibility (remove for v0.7.0)
- 'http://localhost:4567',
+ nconf.get('url') || 'http://localhost:4567',
pattern: /^http(?:s)?:\/\//,
message: 'Base URL must begin with \'http://\' or \'https://\'',
},
@@ -162,7 +161,6 @@ function completeConfigSetup(config, next) {
config.package_manager = nconf.get('package_manager');
}
- nconf.overrides(config);
async.waterfall([
function (next) {
require('./database').init(next);
@@ -171,6 +169,22 @@ function completeConfigSetup(config, next) {
require('./database').createIndices(next);
},
function (next) {
+ // Sanity-check/fix url/port
+ if (!/^http(?:s)?:\/\//.test(config.url)) {
+ config.url = 'http://' + config.url;
+ }
+ var urlObj = url.parse(config.url);
+ if (urlObj.port) {
+ config.port = urlObj.port;
+ }
+ urlObj.pathname = null;
+ urlObj.path = null;
+
+ config.url = url.format(urlObj);
+
+ // ref: https://github.com/indexzero/nconf/issues/300
+ delete config.type;
+
install.save(config, next);
},
], next);
diff --git a/src/views/install/index.tpl b/src/views/install/index.tpl
index 39cc52f305..67cb007cad 100644
--- a/src/views/install/index.tpl
+++ b/src/views/install/index.tpl
@@ -33,6 +33,22 @@
You are just a few steps away from launching your own NodeBB forum!