Commit 6882576c265ff0d371d67f78d09a7711254f2b27
Fix listening on localhost
cel committed on 9/2/2018, 9:16:06 PMParent: a93948ddec0b2c2b49ced0e9c57b64bd2f888606
Files changed
index.js | changed |
index.js | |||
---|---|---|---|
@@ -85,19 +85,24 @@ | |||
85 | 85 … | } | |
86 | 86 … | exports.init = function (sbot, config) { | |
87 | 87 … | var conf = config.npm || {} | |
88 | 88 … | var port = conf.port || 8043 | |
89 | - var host = conf.host || null | ||
89 … | + var host = conf.host || 'localhost' | ||
90 | 90 … | var autoAuth = conf.autoAuth !== false | |
91 … | + var listenUrl | ||
91 | 92 … | ||
92 | 93 … | var server = http.createServer(exports.respond(sbot, config)) | |
93 | 94 … | var getAddress = onceify(function (cb) { | |
94 | 95 … | server.on('error', cb) | |
95 | 96 … | server.listen(port, host, function () { | |
96 | 97 … | 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 | ||
100 | 105 … | if (autoAuth) npmLogin(regUrl, next) | |
101 | 106 … | else next() | |
102 | 107 … | function next(err) { | |
103 | 108 … | cb(err, regUrl) | |
@@ -107,11 +112,16 @@ | |||
107 | 112 … | server.close() | |
108 | 113 … | }) | |
109 | 114 … | }) | |
110 | 115 … | ||
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) { | ||
112 | 122 … | 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) | ||
114 | 124 … | }) | |
115 | 125 … | ||
116 | 126 … | return { | |
117 | 127 … | getAddress: getAddress |
Built with git-ssb-web