-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow listening on multiple endpoints
- Loading branch information
Showing
7 changed files
with
189 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const {URL} = require('url'); | ||
|
||
module.exports = function parseEndpoint(str) { | ||
const url = new URL(str); | ||
|
||
switch (url.protocol) { | ||
case 'pipe:': { | ||
// some special handling | ||
const cutStr = str.replace(/^pipe:/, ''); | ||
if (cutStr.slice(0, 4) !== '\\\\.\\') { | ||
throw new Error(`Invalid Windows named pipe endpoint: ${str}`); | ||
} | ||
return [cutStr]; | ||
} | ||
case 'unix:': | ||
if (!url.pathname) { | ||
throw new Error(`Invalid UNIX domain socket endpoint: ${str}`); | ||
} | ||
return [url.pathname]; | ||
case 'tcp:': | ||
url.port = url.port || '3000'; | ||
return [parseInt(url.port, 10), url.hostname]; | ||
default: | ||
throw new Error(`Unknown --listen endpoint scheme (protocol): ${url.protocol}`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const test = require('ava'); | ||
|
||
const parseEndpoint = require('../lib/parse-endpoint'); | ||
|
||
test('parses TCP URI', async t => { | ||
t.deepEqual(parseEndpoint('tcp://my-host-name.foo.bar:12345'), [12345, 'my-host-name.foo.bar']); | ||
t.deepEqual(parseEndpoint('tcp://0.0.0.0:8080'), [8080, '0.0.0.0']); | ||
|
||
// with the default | ||
t.deepEqual(parseEndpoint('tcp://1.2.3.4'), [3000, '1.2.3.4']); | ||
}); | ||
|
||
test('parses UNIX domain socket URI', async t => { | ||
t.deepEqual(parseEndpoint('unix:/foo/bar.sock'), ['/foo/bar.sock']); | ||
t.deepEqual(parseEndpoint('unix:///foo/bar.sock'), ['/foo/bar.sock']); | ||
}); | ||
|
||
test('parses Windows named pipe URI', async t => { | ||
t.deepEqual(parseEndpoint('pipe:\\\\.\\pipe\\some-name'), ['\\\\.\\pipe\\some-name']); | ||
}); | ||
|
||
test('throws on invalid URI', async t => { | ||
t.throws(() => parseEndpoint('qwertyuiop'), 'Invalid URL: qwertyuiop'); | ||
t.throws(() => parseEndpoint('tcp://:8080'), 'Invalid URL: tcp://:8080'); | ||
}); | ||
|
||
test('throws on invalid scheme (protocol)', async t => { | ||
t.throws(() => parseEndpoint('foobar://blah'), 'Unknown --listen endpoint scheme (protocol): foobar:'); | ||
}); | ||
|
||
test('throws on invalid Windows named pipe', async t => { | ||
t.throws(() => parseEndpoint('pipe:lolsickbro'), 'Invalid Windows named pipe endpoint: pipe:lolsickbro'); | ||
t.throws(() => parseEndpoint('pipe://./pipe/lol'), 'Invalid Windows named pipe endpoint: pipe://./pipe/lol'); | ||
}); | ||
|
||
test('throws on invalid UNIX domain socket', async t => { | ||
t.throws(() => parseEndpoint('unix:'), 'Invalid UNIX domain socket endpoint: unix:'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,6 +185,10 @@ are-we-there-yet@~1.1.2: | |
delegates "^1.0.0" | ||
readable-stream "^2.0.6" | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/arg/-/arg-2.0.0.tgz#c06e7ff69ab05b3a4a03ebe0407fac4cba657545" | ||
|
||
arg@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/arg/-/arg-1.0.1.tgz#892a26d841bd5a64880bbc8f73dd64a705910ca3" | ||
|
@@ -883,6 +887,14 @@ center-align@^0.1.1: | |
align-text "^0.1.3" | ||
lazy-cache "^1.0.3" | ||
|
||
[email protected], chalk@^2.0.0, chalk@^2.3.0: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52" | ||
dependencies: | ||
ansi-styles "^3.2.1" | ||
escape-string-regexp "^1.0.5" | ||
supports-color "^5.3.0" | ||
|
||
chalk@^0.4.0: | ||
version "0.4.0" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f" | ||
|
@@ -901,14 +913,6 @@ chalk@^1.1.3: | |
strip-ansi "^3.0.0" | ||
supports-color "^2.0.0" | ||
|
||
chalk@^2.0.0, chalk@^2.3.0: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52" | ||
dependencies: | ||
ansi-styles "^3.2.1" | ||
escape-string-regexp "^1.0.5" | ||
supports-color "^5.3.0" | ||
|
||
chalk@^2.0.1, chalk@^2.1.0: | ||
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.2.tgz#250dc96b07491bfd601e648d66ddf5f60c7a5c65" | ||
|
@@ -2785,10 +2789,6 @@ mixin-deep@^1.2.0: | |
dependencies: | ||
minimist "0.0.8" | ||
|
||
[email protected]: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.0.tgz#5c0a3f29c8ccffbbb1ec941dcec09d71fa32f36a" | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" | ||
|