git ssb

3+

cel / ssb-npm-registry



Commit 6882576c265ff0d371d67f78d09a7711254f2b27

Fix listening on localhost

cel committed on 9/2/2018, 9:16:06 PM
Parent: a93948ddec0b2c2b49ced0e9c57b64bd2f888606

Files changed

index.jschanged
index.jsView
@@ -85,19 +85,24 @@
8585 }
8686 exports.init = function (sbot, config) {
8787 var conf = config.npm || {}
8888 var port = conf.port || 8043
89- var host = conf.host || null
89 + var host = conf.host || 'localhost'
9090 var autoAuth = conf.autoAuth !== false
91 + var listenUrl
9192
9293 var server = http.createServer(exports.respond(sbot, config))
9394 var getAddress = onceify(function (cb) {
9495 server.on('error', cb)
9596 server.listen(port, host, function () {
9697 server.removeListener('error', cb)
97- var regHost = formatHost(host || 'localhost')
98- var regPort = this.address().port
99- var regUrl = 'http://' + regHost + ':' + regPort + '/'
98 + var addr = this.address()
99 + var listenHost = addr.address
100 + var regHost = listenHost === '::' ? '::1' :
101 + listenHost === '0.0.0.0' ? '127.0.0.1' :
102 + listenHost
103 + var regUrl = 'http://' + formatHost(regHost) + ':' + addr.port
104 + listenUrl = 'http://' + formatHost(listenHost) + ':' + addr.port
100105 if (autoAuth) npmLogin(regUrl, next)
101106 else next()
102107 function next(err) {
103108 cb(err, regUrl)
@@ -107,11 +112,16 @@
107112 server.close()
108113 })
109114 })
110115
111- getAddress(function (err, addr) {
116 + /* getAddress called by local RPC is used to discover the local
117 + * ssb-npm-registry address that can be given to local npm clients. However,
118 + * when running the server we output the address the server is listening on,
119 + * to avoid misleading situations like saying listening on localhost but
120 + * actually listening on a wildcard address. */
121 + getAddress(function (err) {
112122 if (err) return console.error('[npm-registry]', err.stack || err)
113- console.log('[npm-registry] Listening on ' + addr)
123 + console.log('[npm-registry] Listening on ' + listenUrl)
114124 })
115125
116126 return {
117127 getAddress: getAddress

Built with git-ssb-web