1 | export function parseEndpoint(endpoint: string) {
|
2 | const url = new URL(endpoint);
|
3 |
|
4 | switch (url.protocol) {
|
5 | case 'pipe:': {
|
6 |
|
7 | const cutStr = endpoint.replace(/^pipe:/, '');
|
8 | if (!cutStr.startsWith('\\\\.\\')) {
|
9 | throw new Error(`Invalid Windows named pipe endpoint: ${endpoint}`);
|
10 | }
|
11 | return [cutStr];
|
12 | }
|
13 | case 'unix:':
|
14 | if (!url.pathname) {
|
15 | throw new Error(`Invalid UNIX domain socket endpoint: ${endpoint}`);
|
16 | }
|
17 | return [url.pathname];
|
18 | case 'tcp:':
|
19 | url.port = url.port || '3000';
|
20 | return [parseInt(url.port, 10).toString(), url.hostname];
|
21 | default:
|
22 | throw new Error(
|
23 | `Unknown --listen endpoint scheme (protocol): ${url.protocol}`,
|
24 | );
|
25 | }
|
26 | }
|