MCPcopy Index your code
hub / github.com/vercel/micro / parseEndpoint

Function parseEndpoint

packages/micro/src/lib/parse-endpoint.ts:1–26  ·  view source on GitHub ↗
(endpoint: string)

Source from the content-addressed store, hash-verified

1export function parseEndpoint(endpoint: string) {
2 const url = new URL(endpoint);
3
4 switch (url.protocol) {
5 case 'pipe:': {
6 // some special handling
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}

Callers 1

parse-endpoint.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected