mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
cli.js: add https support. Issue #71.
This commit is contained in:
parent
97c7c6814f
commit
61fff273fc
2 changed files with 34 additions and 2 deletions
|
@ -84,6 +84,12 @@ packages:
|
||||||
# to listen on INADDR_ANY use 0.0.0.0:4873
|
# to listen on INADDR_ANY use 0.0.0.0:4873
|
||||||
#listen: localhost:4873
|
#listen: localhost:4873
|
||||||
|
|
||||||
|
# Configure HTTPS. Set enable to true and supply a key and cert to enable HTTPS.
|
||||||
|
https:
|
||||||
|
enable: false
|
||||||
|
key: path/to/server.key
|
||||||
|
cert: path/to/server.crt
|
||||||
|
|
||||||
# type: file | stdout | stderr
|
# type: file | stdout | stderr
|
||||||
# level: trace | debug | info | http (default) | warn | error | fatal
|
# level: trace | debug | info | http (default) | warn | error | fatal
|
||||||
#
|
#
|
||||||
|
|
30
lib/cli.js
30
lib/cli.js
|
@ -19,7 +19,10 @@ var logger = require('./logger')
|
||||||
logger.setup() // default setup
|
logger.setup() // default setup
|
||||||
|
|
||||||
var commander = require('commander')
|
var commander = require('commander')
|
||||||
|
var constants = require('constants')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
var http = require('http')
|
||||||
|
var https = require('https')
|
||||||
var YAML = require('js-yaml')
|
var YAML = require('js-yaml')
|
||||||
var Path = require('path')
|
var Path = require('path')
|
||||||
var server = require('./index')
|
var server = require('./index')
|
||||||
|
@ -73,16 +76,39 @@ function get_hostport() {
|
||||||
|
|
||||||
function afterConfigLoad() {
|
function afterConfigLoad() {
|
||||||
if (!config.self_path) config.self_path = Path.resolve(config_path)
|
if (!config.self_path) config.self_path = Path.resolve(config_path)
|
||||||
|
if (!config.https) config.https = { enable: false };
|
||||||
|
|
||||||
var hostport = get_hostport()
|
var hostport = get_hostport()
|
||||||
server(config)
|
var app = server(config);
|
||||||
|
var webServer;
|
||||||
|
|
||||||
|
if (config.https.enable === true) { // https
|
||||||
|
try {
|
||||||
|
webServer = https.createServer({
|
||||||
|
secureProtocol: 'SSLv23_method', // disable insecure SSLv2 and SSLv3
|
||||||
|
secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,
|
||||||
|
key: fs.readFileSync(config.https.key),
|
||||||
|
cert: fs.readFileSync(config.https.cert)
|
||||||
|
}, app);
|
||||||
|
} catch (err) { // catch errors related to certificate loading
|
||||||
|
logger.logger.fatal({err: err}, 'cannot create server: @{err.message}')
|
||||||
|
process.exit(2)
|
||||||
|
}
|
||||||
|
} else { // http
|
||||||
|
webServer = http.createServer(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
webServer
|
||||||
.listen(hostport[1], hostport[0])
|
.listen(hostport[1], hostport[0])
|
||||||
.on('error', function(err) {
|
.on('error', function(err) {
|
||||||
logger.logger.fatal({ err: err }, 'cannot create server: @{err.message}')
|
logger.logger.fatal({ err: err }, 'cannot create server: @{err.message}')
|
||||||
process.exit(2)
|
process.exit(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.logger.warn({ addr: 'http://'+hostport[0]+':'+hostport[1]+'/', version: 'Sinopia/'+pkg.version }, 'http address - @{addr}')
|
logger.logger.warn({
|
||||||
|
addr: (config.https.enable === true ? 'https' : 'http') + '://'+hostport[0]+':'+hostport[1]+'/',
|
||||||
|
version: 'Sinopia/'+pkg.version,
|
||||||
|
}, 'http address - @{addr}')
|
||||||
|
|
||||||
// undocumented stuff for tests
|
// undocumented stuff for tests
|
||||||
if (typeof(process.send) === 'function') {
|
if (typeof(process.send) === 'function') {
|
||||||
|
|
Loading…
Reference in a new issue