You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/install.js

121 lines
3.6 KiB
JavaScript

var async = require('async'),
utils = require('../public/src/utils.js'),
fs = require('fs'),
url = require('url'),
path = require('path'),
meta = require('./meta'),
install = {
questions: [
'base_url|Publically accessible URL of this installation? (http://localhost)',
'port|Port number of your install? (4567)',
'use_port|Will you be using a port number to access NodeBB? (y)',
'redis:host|Host IP or address of your Redis instance? (127.0.0.1)',
'redis:port|Host port of your Redis instance? (6379)',
'redis:password|Password of your Redis database? (no password)',
'secret|Your NodeBB secret? (keyboard mash for a bit here)'
],
defaults: {
"base_url": 'http://localhost',
"port": 4567,
"use_port": true,
12 years ago
"redis": {
"host": '127.0.0.1',
"port": 6379,
"password": ''
},
"secret": utils.generateUUID(),
"bcrypt_rounds": 12,
"upload_path": '/public/uploads'
},
ask: function(question, callback) {
process.stdin.resume();
process.stdout.write(question + ': ');
process.stdin.once('data', function(data) {
callback(data.toString().trim());
});
},
setup: function(callback) {
var config = {};
for(d in install.defaults) config[d] = install.defaults[d];
async.eachSeries(install.questions, function(question, next) {
var question = question.split('|');
install.ask(question[1], function(value) {
switch(question[0]) {
case 'use_port':
value = value.toLowerCase();
if (['y', 'yes', ''].indexOf(value) === -1) config[question[0]] = false;
break;
case 'redis:host':
config.redis = config.redis || {};
12 years ago
if (value !== '') config.redis.host = value;
break;
case 'redis:port':
config.redis = config.redis || {};
12 years ago
if (value !== '') config.redis.port = value;
break;
case 'redis:password':
config.redis = config.redis || {};
12 years ago
if (value !== '') config.redis.password = value;
break;
default:
if (value !== '') config[question[0]] = value;
break;
}
next();
});
}, function() {
var urlObject = url.parse(config.base_url),
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
host = urlObject.host,
protocol = urlObject.protocol,
server_conf = config,
client_conf = {
socket: {
address: protocol + '//' + host + (config.use_port ? ':' + config.port : '')
},
api_url: protocol + '//' + host + (config.use_port ? ':' + config.port : '') + relative_path + '/api/',
relative_path: relative_path
};
server_conf.base_url = protocol + '//' + host;
server_conf.relative_path = relative_path;
meta.configs.set('postDelay', 10000);
meta.configs.set('minimumPostLength', 8);
meta.configs.set('minimumTitleLength', 3);
12 years ago
meta.configs.set('minimumUsernameLength', 2);
meta.configs.set('maximumUsernameLength', 16);
meta.configs.set('minimumPasswordLength', 6);
meta.configs.set('imgurClientID', '');
install.save(server_conf, client_conf, callback);
});
},
save: function(server_conf, client_conf, callback) {
// Server Config
async.parallel([
function(next) {
fs.writeFile(path.join(__dirname, '../', 'config.json'), JSON.stringify(server_conf, null, 4), function(err) {
next(err);
});
},
function(next) {
fs.writeFile(path.join(__dirname, '../', 'public', 'config.json'), JSON.stringify(client_conf, null, 4), function(err) {
next(err);
});
}
], function(err) {
process.stdout.write(
"\n\nConfiguration Saved OK\n\n"
);
callback(err);
});
}
};
module.exports = install;