mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-27 22:59:51 -05:00
add a code to bind on unix sockets
use "listen: 'unix:sinopia.sock'" for this
This commit is contained in:
parent
137fd5978f
commit
97386397c2
4 changed files with 48 additions and 20 deletions
|
@ -91,6 +91,7 @@ packages:
|
|||
# - 0.0.0.0:4873 # listen on all addresses (INADDR_ANY)
|
||||
# - https://example.org:4873 # if you want to use https
|
||||
# - [::1]:4873 # ipv6
|
||||
# - unix:/tmp/sinopia.sock # unix socket
|
||||
|
||||
# Configure HTTPS, it is required if you use "https" protocol above.
|
||||
#https:
|
||||
|
|
26
lib/cli.js
26
lib/cli.js
|
@ -77,16 +77,16 @@ function get_listen_addresses() {
|
|||
}
|
||||
|
||||
addresses = addresses.map(function(addr) {
|
||||
addr = Utils.parse_address(addr)
|
||||
var parsed_addr = Utils.parse_address(addr)
|
||||
|
||||
if (!addr) {
|
||||
if (!parsed_addr) {
|
||||
logger.logger.warn({ addr: addr },
|
||||
'invalid address - @{addr}, we expect a port (e.g. "4873"),'
|
||||
+ ' host:port (e.g. "localhost:4873") or full url'
|
||||
+ ' (e.g. "http://localhost:4873/")')
|
||||
}
|
||||
|
||||
return addr
|
||||
return parsed_addr
|
||||
|
||||
}).filter(Boolean)
|
||||
|
||||
|
@ -142,19 +142,25 @@ function afterConfigLoad() {
|
|||
}
|
||||
|
||||
webServer
|
||||
.listen(addr.port, addr.host)
|
||||
.listen(addr.port || addr.path, addr.host)
|
||||
.on('error', function(err) {
|
||||
logger.logger.fatal({ err: err }, 'cannot create server: @{err.message}')
|
||||
process.exit(2)
|
||||
})
|
||||
|
||||
logger.logger.warn({
|
||||
addr: URL.format({
|
||||
protocol: addr.proto,
|
||||
hostname: addr.host,
|
||||
port: addr.port,
|
||||
pathname: '/',
|
||||
}),
|
||||
addr: ( addr.path
|
||||
? URL.format({
|
||||
protocol: 'unix',
|
||||
pathname: addr.path,
|
||||
})
|
||||
: URL.format({
|
||||
protocol: addr.proto,
|
||||
hostname: addr.host,
|
||||
port: addr.port,
|
||||
pathname: '/',
|
||||
})
|
||||
),
|
||||
version: 'Sinopia/'+pkg.version,
|
||||
}, 'http address - @{addr}')
|
||||
})
|
||||
|
|
29
lib/utils.js
29
lib/utils.js
|
@ -126,23 +126,34 @@ module.exports.parse_address = function parse_address(addr) {
|
|||
//
|
||||
// Allow:
|
||||
//
|
||||
// - https:localhost:1234 - protocol + host + port
|
||||
// - localhost:1234 - host + port
|
||||
// - 1234 - port
|
||||
// - http::1234 - protocol + port
|
||||
// - https://localhost:443/ - full url + https
|
||||
// - http://[::1]:443/ - ipv6
|
||||
// - https:localhost:1234 - protocol + host + port
|
||||
// - localhost:1234 - host + port
|
||||
// - 1234 - port
|
||||
// - http::1234 - protocol + port
|
||||
// - https://localhost:443/ - full url + https
|
||||
// - http://[::1]:443/ - ipv6
|
||||
// - unix:/tmp/http.sock - unix sockets
|
||||
// - https://unix:/tmp/http.sock - unix sockets (https)
|
||||
//
|
||||
// TODO: refactor it to something more reasonable?
|
||||
//
|
||||
// protocol : // ( host )|( ipv6 ): port /
|
||||
var m = /^((https?):(\/\/)?)?((([^\/:]*)|\[([^\[\]]+)\]):)?(\d+)\/?$/.exec(addr)
|
||||
|
||||
if (!m) return null
|
||||
|
||||
return {
|
||||
if (m) return {
|
||||
proto: m[2] || 'http',
|
||||
host: m[6] || m[7] || 'localhost',
|
||||
port: m[8] || '4873',
|
||||
}
|
||||
|
||||
var m = /^((https?):(\/\/)?)?unix:(.*)$/.exec(addr)
|
||||
|
||||
if (m) return {
|
||||
proto: m[2] || 'http',
|
||||
path: m[4],
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
// function filters out bad semver versions and sorts the array
|
||||
|
|
|
@ -6,12 +6,17 @@ describe('Parse address', function() {
|
|||
it(what, function() {
|
||||
if (proto === null) {
|
||||
assert.strictEqual(parse(what), null)
|
||||
} else {
|
||||
} else if (port) {
|
||||
assert.deepEqual(parse(what), {
|
||||
proto: proto,
|
||||
host: host,
|
||||
port: port,
|
||||
})
|
||||
} else {
|
||||
assert.deepEqual(parse(what), {
|
||||
proto: proto,
|
||||
path: host,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -26,7 +31,12 @@ describe('Parse address', function() {
|
|||
addTest('[::1]:4873', 'http', '::1', '4873')
|
||||
addTest('https:[::1]:4873', 'https', '::1', '4873')
|
||||
|
||||
addTest('unix:/tmp/foo.sock', 'http', '/tmp/foo.sock')
|
||||
addTest('http:unix:foo.sock', 'http', 'foo.sock')
|
||||
addTest('https://unix:foo.sock', 'https', 'foo.sock')
|
||||
|
||||
addTest('blah', null)
|
||||
addTest('blah://4873', null)
|
||||
addTest('https://blah:4873///', null)
|
||||
addTest('unix:1234', 'http', 'unix', '1234') // not unix socket
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue