2017-02-26 23:06:20 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
module.exports = (port, spinner) => {
|
2017-04-28 21:58:38 +00:00
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
const ROOTPATH = process.cwd()
|
|
|
|
const SERVERPATH = path.join(ROOTPATH, 'server')
|
2017-02-26 23:06:20 +00:00
|
|
|
const IS_DEBUG = process.env.NODE_ENV === 'development'
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Load modules
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const compression = require('compression')
|
|
|
|
const express = require('express')
|
|
|
|
const favicon = require('serve-favicon')
|
|
|
|
const http = require('http')
|
2017-03-05 04:20:22 +00:00
|
|
|
const Promise = require('bluebird')
|
2017-03-25 22:21:14 +00:00
|
|
|
const fs = Promise.promisifyAll(require('fs-extra'))
|
2017-03-25 21:03:09 +00:00
|
|
|
const yaml = require('js-yaml')
|
2017-03-05 04:20:22 +00:00
|
|
|
const _ = require('lodash')
|
2017-02-26 23:06:20 +00:00
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Define Express App
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
var app = express()
|
|
|
|
app.use(compression())
|
|
|
|
|
2017-03-29 02:29:53 +00:00
|
|
|
var server
|
|
|
|
|
2017-02-26 23:06:20 +00:00
|
|
|
// ----------------------------------------
|
|
|
|
// Public Assets
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
app.use(favicon(path.join(ROOTPATH, 'assets', 'favicon.ico')))
|
|
|
|
app.use(express.static(path.join(ROOTPATH, 'assets')))
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// View Engine Setup
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2017-04-28 21:58:38 +00:00
|
|
|
app.set('views', path.join(SERVERPATH, 'views'))
|
2017-02-26 23:06:20 +00:00
|
|
|
app.set('view engine', 'pug')
|
|
|
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
app.use(bodyParser.urlencoded({ extended: false }))
|
|
|
|
|
|
|
|
app.locals._ = require('lodash')
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Controllers
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
app.get('*', (req, res) => {
|
2017-03-25 21:03:09 +00:00
|
|
|
let langs = []
|
2017-03-26 03:17:05 +00:00
|
|
|
let conf = {}
|
2017-03-25 21:03:09 +00:00
|
|
|
try {
|
2017-04-28 21:58:38 +00:00
|
|
|
langs = yaml.safeLoad(fs.readFileSync(path.join(SERVERPATH, 'app/data.yml'), 'utf8')).langs
|
|
|
|
conf = yaml.safeLoad(fs.readFileSync(path.join(ROOTPATH, 'config.yml'), 'utf8'))
|
2017-03-25 21:03:09 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2017-03-26 03:17:05 +00:00
|
|
|
res.render('configure/index', { langs, conf })
|
2017-02-26 23:06:20 +00:00
|
|
|
})
|
|
|
|
|
2017-03-25 21:03:09 +00:00
|
|
|
/**
|
|
|
|
* Perform basic system checks
|
|
|
|
*/
|
2017-03-05 04:20:22 +00:00
|
|
|
app.post('/syscheck', (req, res) => {
|
|
|
|
Promise.mapSeries([
|
|
|
|
() => {
|
|
|
|
const semver = require('semver')
|
|
|
|
if (!semver.satisfies(semver.clean(process.version), '>=4.6.0')) {
|
2017-03-15 01:23:14 +00:00
|
|
|
throw new Error('Node.js version is too old. Minimum is v4.6.0.')
|
2017-03-05 04:20:22 +00:00
|
|
|
}
|
2017-03-15 01:23:14 +00:00
|
|
|
return 'Node.js ' + process.version + ' detected. Minimum is v4.6.0.'
|
2017-03-05 04:20:22 +00:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return Promise.try(() => {
|
|
|
|
require('crypto')
|
|
|
|
}).catch(err => { // eslint-disable-line handle-callback-err
|
|
|
|
throw new Error('Crypto Node.js module is not available.')
|
2017-03-15 01:23:14 +00:00
|
|
|
}).return('Node.js Crypto module is available.')
|
2017-03-05 04:20:22 +00:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
const exec = require('child_process').exec
|
|
|
|
const semver = require('semver')
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
exec('git --version', (err, stdout, stderr) => {
|
|
|
|
if (err || stdout.length < 3) {
|
|
|
|
reject(new Error('Git is not installed or not reachable from PATH.'))
|
|
|
|
}
|
2017-04-12 00:17:34 +00:00
|
|
|
let gitver = _.head(stdout.match(/[\d]+\.[\d]+\.[\d]+/g))
|
2017-04-07 19:22:20 +00:00
|
|
|
if (!semver.satisfies(semver.clean(gitver), '>=2.7.4')) {
|
2017-04-06 00:33:16 +00:00
|
|
|
reject(new Error('Git version is too old. Minimum is v2.7.4.'))
|
2017-03-05 04:20:22 +00:00
|
|
|
}
|
2017-04-06 00:33:16 +00:00
|
|
|
resolve('Git v' + gitver + ' detected. Minimum is v2.7.4.')
|
2017-03-05 04:20:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2017-03-15 01:23:14 +00:00
|
|
|
() => {
|
|
|
|
const os = require('os')
|
2017-05-02 02:01:45 +00:00
|
|
|
if (os.totalmem() < 1000 * 1000 * 768) {
|
2017-03-15 01:23:14 +00:00
|
|
|
throw new Error('Not enough memory. Minimum is 768 MB.')
|
|
|
|
}
|
|
|
|
return _.round(os.totalmem() / (1024 * 1024)) + ' MB of system memory available. Minimum is 768 MB.'
|
|
|
|
},
|
2017-03-05 04:20:22 +00:00
|
|
|
() => {
|
|
|
|
let fs = require('fs')
|
|
|
|
return Promise.try(() => {
|
|
|
|
fs.accessSync(path.join(ROOTPATH, 'config.yml'), (fs.constants || fs).W_OK)
|
|
|
|
}).catch(err => { // eslint-disable-line handle-callback-err
|
|
|
|
throw new Error('config.yml file is not writable by Node.js process or was not created properly.')
|
2017-03-15 01:23:14 +00:00
|
|
|
}).return('config.yml is writable by the setup process.')
|
2017-03-05 04:20:22 +00:00
|
|
|
}
|
|
|
|
], test => { return test() }).then(results => {
|
2017-03-15 01:23:14 +00:00
|
|
|
res.json({ ok: true, results })
|
2017-03-05 04:20:22 +00:00
|
|
|
}).catch(err => {
|
|
|
|
res.json({ ok: false, error: err.message })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-25 21:03:09 +00:00
|
|
|
/**
|
|
|
|
* Check the DB connection
|
|
|
|
*/
|
|
|
|
app.post('/dbcheck', (req, res) => {
|
|
|
|
let mongo = require('mongodb').MongoClient
|
2017-04-19 00:23:42 +00:00
|
|
|
let mongoURI = (_.startsWith(req.body.db, '$')) ? process.env[req.body.db.slice(1)] : req.body.db
|
|
|
|
mongo.connect(mongoURI, {
|
2017-03-25 21:03:09 +00:00
|
|
|
autoReconnect: false,
|
|
|
|
reconnectTries: 2,
|
|
|
|
reconnectInterval: 1000,
|
|
|
|
connectTimeoutMS: 5000,
|
|
|
|
socketTimeoutMS: 5000
|
|
|
|
}, (err, db) => {
|
|
|
|
if (err === null) {
|
|
|
|
// Try to create a test collection
|
|
|
|
db.createCollection('test', (err, results) => {
|
|
|
|
if (err === null) {
|
|
|
|
// Try to drop test collection
|
|
|
|
db.dropCollection('test', (err, results) => {
|
|
|
|
if (err === null) {
|
|
|
|
res.json({ ok: true })
|
|
|
|
} else {
|
|
|
|
res.json({ ok: false, error: 'Unable to delete test collection. Verify permissions. ' + err.message })
|
|
|
|
}
|
|
|
|
db.close()
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.json({ ok: false, error: 'Unable to create test collection. Verify permissions. ' + err.message })
|
|
|
|
db.close()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.json({ ok: false, error: err.message })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the Git connection
|
|
|
|
*/
|
|
|
|
app.post('/gitcheck', (req, res) => {
|
|
|
|
const exec = require('execa')
|
2017-03-25 22:21:14 +00:00
|
|
|
const url = require('url')
|
2017-03-25 21:03:09 +00:00
|
|
|
|
|
|
|
const dataDir = path.resolve(ROOTPATH, req.body.pathData)
|
|
|
|
const gitDir = path.resolve(ROOTPATH, req.body.pathRepo)
|
2017-03-25 22:21:14 +00:00
|
|
|
|
2017-03-26 03:17:05 +00:00
|
|
|
let gitRemoteUrl = ''
|
|
|
|
|
|
|
|
if (req.body.gitUseRemote === true) {
|
|
|
|
let urlObj = url.parse(req.body.gitUrl)
|
|
|
|
if (req.body.gitAuthType === 'basic') {
|
|
|
|
urlObj.auth = req.body.gitAuthUser + ':' + req.body.gitAuthPass
|
|
|
|
}
|
|
|
|
gitRemoteUrl = url.format(urlObj)
|
2017-03-25 22:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Promise.mapSeries([
|
|
|
|
() => {
|
|
|
|
return fs.ensureDirAsync(dataDir).return('Data directory path is valid.')
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return fs.ensureDirAsync(gitDir).return('Git directory path is valid.')
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
return exec.stdout('git', ['init'], { cwd: gitDir }).then(result => {
|
|
|
|
return 'Local git repository has been initialized.'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-04-29 22:34:00 +00:00
|
|
|
return exec.stdout('git', ['config', '--local', 'user.name', 'Wiki'], { cwd: gitDir }).then(result => {
|
2017-03-25 22:21:14 +00:00
|
|
|
return 'Git Signature Name has been set successfully.'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-04-29 22:34:00 +00:00
|
|
|
return exec.stdout('git', ['config', '--local', 'user.email', req.body.gitServerEmail], { cwd: gitDir }).then(result => {
|
2017-03-25 22:21:14 +00:00
|
|
|
return 'Git Signature Name has been set successfully.'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-03-25 22:21:14 +00:00
|
|
|
return exec.stdout('git', ['config', '--local', '--bool', 'http.sslVerify', req.body.gitAuthSSL], { cwd: gitDir }).then(result => {
|
|
|
|
return 'Git SSL Verify flag has been set successfully.'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-03-25 22:21:14 +00:00
|
|
|
if (req.body.gitAuthType === 'ssh') {
|
|
|
|
return exec.stdout('git', ['config', '--local', 'core.sshCommand', 'ssh -i "' + req.body.gitAuthSSHKey + '" -o StrictHostKeyChecking=no'], { cwd: gitDir }).then(result => {
|
|
|
|
return 'Git SSH Private Key path has been set successfully.'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-04-30 04:49:26 +00:00
|
|
|
return exec.stdout('git', ['remote', 'rm', 'origin'], { cwd: gitDir }).catch(err => {
|
|
|
|
if (_.includes(err.message, 'No such remote') || _.includes(err.message, 'Could not remove')) {
|
2017-03-25 22:21:14 +00:00
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}).then(() => {
|
|
|
|
return exec.stdout('git', ['remote', 'add', 'origin', gitRemoteUrl], { cwd: gitDir }).then(result => {
|
|
|
|
return 'Git Remote was added successfully.'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
if (req.body.gitUseRemote === false) { return false }
|
2017-03-25 22:21:14 +00:00
|
|
|
return exec.stdout('git', ['pull', 'origin', req.body.gitBranch], { cwd: gitDir }).then(result => {
|
|
|
|
return 'Git Pull operation successful.'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
], step => { return step() }).then(results => {
|
|
|
|
return res.json({ ok: true, results: _.without(results, false) })
|
2017-03-25 21:03:09 +00:00
|
|
|
}).catch(err => {
|
2017-03-25 22:21:14 +00:00
|
|
|
let errMsg = (err.stderr) ? err.stderr.replace(/(error:|warning:|fatal:)/gi, '').replace(/ \s+/g, ' ') : err.message
|
|
|
|
res.json({ ok: false, error: errMsg })
|
2017-03-25 21:03:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
/**
|
2017-03-26 03:17:05 +00:00
|
|
|
* Finalize
|
2017-03-25 21:03:09 +00:00
|
|
|
*/
|
|
|
|
app.post('/finalize', (req, res) => {
|
2017-03-26 03:17:05 +00:00
|
|
|
const bcrypt = require('bcryptjs-then')
|
|
|
|
const crypto = Promise.promisifyAll(require('crypto'))
|
2017-03-25 21:03:09 +00:00
|
|
|
let mongo = require('mongodb').MongoClient
|
2017-03-26 03:17:05 +00:00
|
|
|
|
|
|
|
Promise.join(
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
mongo.connect(req.body.db, {
|
|
|
|
autoReconnect: false,
|
|
|
|
reconnectTries: 2,
|
|
|
|
reconnectInterval: 1000,
|
|
|
|
connectTimeoutMS: 5000,
|
|
|
|
socketTimeoutMS: 5000
|
|
|
|
}, (err, db) => {
|
2017-03-25 21:03:09 +00:00
|
|
|
if (err === null) {
|
2017-03-26 03:17:05 +00:00
|
|
|
db.createCollection('users', { strict: false }, (err, results) => {
|
2017-03-25 21:03:09 +00:00
|
|
|
if (err === null) {
|
2017-03-26 03:17:05 +00:00
|
|
|
bcrypt.hash(req.body.adminPassword).then(adminPwdHash => {
|
|
|
|
db.collection('users').findOneAndUpdate({
|
|
|
|
provider: 'local',
|
|
|
|
email: req.body.adminEmail
|
|
|
|
}, {
|
|
|
|
provider: 'local',
|
|
|
|
email: req.body.adminEmail,
|
|
|
|
name: 'Administrator',
|
|
|
|
password: adminPwdHash,
|
|
|
|
rights: [{
|
|
|
|
role: 'admin',
|
|
|
|
path: '/',
|
|
|
|
exact: false,
|
|
|
|
deny: false
|
|
|
|
}],
|
|
|
|
updatedAt: new Date(),
|
|
|
|
createdAt: new Date()
|
|
|
|
}, {
|
|
|
|
upsert: true,
|
|
|
|
returnOriginal: false
|
|
|
|
}, (err, results) => {
|
|
|
|
if (err === null) {
|
|
|
|
resolve(true)
|
|
|
|
} else {
|
|
|
|
reject(err)
|
|
|
|
}
|
|
|
|
db.close()
|
|
|
|
})
|
|
|
|
})
|
2017-03-25 21:03:09 +00:00
|
|
|
} else {
|
2017-03-26 03:17:05 +00:00
|
|
|
reject(err)
|
|
|
|
db.close()
|
2017-03-25 21:03:09 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
2017-03-26 03:17:05 +00:00
|
|
|
reject(err)
|
2017-03-25 21:03:09 +00:00
|
|
|
}
|
|
|
|
})
|
2017-03-26 03:17:05 +00:00
|
|
|
}),
|
2017-04-28 21:58:38 +00:00
|
|
|
fs.readFileAsync(path.join(ROOTPATH, 'config.yml'), 'utf8').then(confRaw => {
|
2017-03-26 03:17:05 +00:00
|
|
|
let conf = yaml.safeLoad(confRaw)
|
|
|
|
conf.title = req.body.title
|
|
|
|
conf.host = req.body.host
|
|
|
|
conf.port = req.body.port
|
|
|
|
conf.paths = {
|
|
|
|
repo: req.body.pathRepo,
|
|
|
|
data: req.body.pathData
|
|
|
|
}
|
|
|
|
conf.uploads = {
|
|
|
|
maxImageFileSize: (conf.uploads && _.isNumber(conf.uploads.maxImageFileSize)) ? conf.uploads.maxImageFileSize : 3,
|
|
|
|
maxOtherFileSize: (conf.uploads && _.isNumber(conf.uploads.maxOtherFileSize)) ? conf.uploads.maxOtherFileSize : 100
|
|
|
|
}
|
|
|
|
conf.lang = req.body.lang
|
2017-05-04 23:09:17 +00:00
|
|
|
conf.public = (req.body.public === true)
|
2017-03-26 03:17:05 +00:00
|
|
|
if (conf.auth && conf.auth.local) {
|
|
|
|
conf.auth.local = { enabled: true }
|
|
|
|
} else {
|
|
|
|
conf.auth = { local: { enabled: true } }
|
|
|
|
}
|
|
|
|
conf.db = req.body.db
|
|
|
|
if (req.body.gitUseRemote === false) {
|
|
|
|
conf.git = false
|
|
|
|
} else {
|
|
|
|
conf.git = {
|
|
|
|
url: req.body.gitUrl,
|
|
|
|
branch: req.body.gitBranch,
|
|
|
|
auth: {
|
|
|
|
type: req.body.gitAuthType,
|
|
|
|
username: req.body.gitAuthUser,
|
|
|
|
password: req.body.gitAuthPass,
|
|
|
|
privateKey: req.body.gitAuthSSHKey,
|
|
|
|
sslVerify: (req.body.gitAuthSSL === true)
|
|
|
|
},
|
2017-04-29 22:34:00 +00:00
|
|
|
showUserEmail: (req.body.gitShowUserEmail === true),
|
|
|
|
serverEmail: req.body.gitServerEmail
|
2017-03-26 03:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return crypto.randomBytesAsync(32).then(buf => {
|
|
|
|
conf.sessionSecret = buf.toString('hex')
|
|
|
|
confRaw = yaml.safeDump(conf)
|
2017-04-28 21:58:38 +00:00
|
|
|
return fs.writeFileAsync(path.join(ROOTPATH, 'config.yml'), confRaw)
|
2017-03-26 03:17:05 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
).then(() => {
|
2017-04-23 14:56:14 +00:00
|
|
|
if (process.env.IS_HEROKU) {
|
2017-04-28 21:58:38 +00:00
|
|
|
return fs.outputJsonAsync(path.join(SERVERPATH, 'app/heroku.json'), { configured: true })
|
2017-04-23 14:56:14 +00:00
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}).then(() => {
|
2017-03-26 03:17:05 +00:00
|
|
|
res.json({ ok: true })
|
|
|
|
}).catch(err => {
|
|
|
|
res.json({ ok: false, error: err.message })
|
2017-03-25 21:03:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-03-29 02:29:53 +00:00
|
|
|
/**
|
|
|
|
* Restart in normal mode
|
|
|
|
*/
|
|
|
|
app.post('/restart', (req, res) => {
|
|
|
|
res.status(204).end()
|
|
|
|
server.destroy(() => {
|
|
|
|
spinner.text = 'Setup wizard terminated. Restarting in normal mode...'
|
|
|
|
_.delay(() => {
|
|
|
|
const exec = require('execa')
|
|
|
|
exec.stdout('node', ['wiki', 'start']).then(result => {
|
|
|
|
spinner.succeed('Wiki.js is now running in normal mode!')
|
|
|
|
process.exit(0)
|
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-02-26 23:06:20 +00:00
|
|
|
// ----------------------------------------
|
|
|
|
// Error handling
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
app.use(function (req, res, next) {
|
|
|
|
var err = new Error('Not Found')
|
|
|
|
err.status = 404
|
|
|
|
next(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.use(function (err, req, res, next) {
|
|
|
|
res.status(err.status || 500)
|
|
|
|
res.send({
|
|
|
|
message: err.message,
|
|
|
|
error: IS_DEBUG ? err : {}
|
|
|
|
})
|
|
|
|
spinner.fail(err.message)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Start HTTP server
|
|
|
|
// ----------------------------------------
|
|
|
|
|
|
|
|
spinner.text = 'Starting HTTP server...'
|
|
|
|
|
|
|
|
app.set('port', port)
|
2017-03-29 02:29:53 +00:00
|
|
|
server = http.createServer(app)
|
2017-02-26 23:06:20 +00:00
|
|
|
server.listen(port)
|
2017-03-29 02:29:53 +00:00
|
|
|
|
|
|
|
var openConnections = []
|
|
|
|
|
|
|
|
server.on('connection', (conn) => {
|
|
|
|
let key = conn.remoteAddress + ':' + conn.remotePort
|
|
|
|
openConnections[key] = conn
|
|
|
|
conn.on('close', () => {
|
|
|
|
delete openConnections[key]
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
server.destroy = (cb) => {
|
|
|
|
server.close(cb)
|
|
|
|
for (let key in openConnections) {
|
|
|
|
openConnections[key].destroy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-26 23:06:20 +00:00
|
|
|
server.on('error', (error) => {
|
|
|
|
if (error.syscall !== 'listen') {
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (error.code) {
|
|
|
|
case 'EACCES':
|
|
|
|
spinner.fail('Listening on port ' + port + ' requires elevated privileges!')
|
2017-04-05 02:04:17 +00:00
|
|
|
return process.exit(1)
|
2017-02-26 23:06:20 +00:00
|
|
|
case 'EADDRINUSE':
|
|
|
|
spinner.fail('Port ' + port + ' is already in use!')
|
2017-04-05 02:04:17 +00:00
|
|
|
return process.exit(1)
|
2017-02-26 23:06:20 +00:00
|
|
|
default:
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
server.on('listening', () => {
|
|
|
|
spinner.text = 'Browse to http://localhost:' + port + ' to configure Wiki.js!'
|
|
|
|
})
|
|
|
|
}
|