MCPcopy Index your code
hub / github.com/callstack/agent-device / startProxy

Function startProxy

src/cli/commands/proxy.ts:32–67  ·  view source on GitHub ↗
(flags: CliFlags)

Source from the content-addressed store, hash-verified

30};
31
32async function startProxy(flags: CliFlags): Promise<ProxyStartup> {
33 const settings = resolveClientSettings({
34 session: 'default',
35 command: 'proxy',
36 positionals: [],
37 flags: {
38 stateDir: flags.stateDir,
39 daemonBaseUrl: '',
40 daemonTransport: 'http',
41 daemonServerMode: 'http',
42 },
43 });
44 const daemon = await ensureDaemon(settings);
45 const upstreamBaseUrl = resolveLocalDaemonBaseUrl(daemon.info.httpPort);
46 const token = resolveProxyClientToken(flags);
47 const server = createDaemonProxyServer({
48 upstreamBaseUrl,
49 upstreamToken: daemon.info.token,
50 clientToken: token,
51 });
52 const host = flags.proxyHost?.trim() || '127.0.0.1';
53 const port = flags.proxyPort ?? 0;
54 await listen(server, host, port);
55 const address = server.address();
56 if (!address || typeof address === 'string') {
57 throw new AppError('COMMAND_FAILED', 'Proxy did not bind to a TCP address.');
58 }
59 const proxyBaseUrl = `http://${formatHostForUrl(address.address)}:${address.port}`;
60 return {
61 proxyBaseUrl,
62 agentDeviceBaseUrl: buildDaemonHttpBaseUrl(proxyBaseUrl),
63 token,
64 upstreamBaseUrl,
65 stateDir: settings.paths.baseDir,
66 };
67}
68
69function resolveLocalDaemonBaseUrl(httpPort: number | undefined): string {
70 if (!httpPort) {

Callers 1

proxyCommandFunction · 0.85

Calls 8

resolveClientSettingsFunction · 0.90
ensureDaemonFunction · 0.90
createDaemonProxyServerFunction · 0.90
buildDaemonHttpBaseUrlFunction · 0.90
resolveProxyClientTokenFunction · 0.85
listenFunction · 0.85
formatHostForUrlFunction · 0.85

Tested by

no test coverage detected