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

Function handleProxyRequest

src/remote/daemon-proxy.ts:46–80  ·  view source on GitHub ↗
(
  req: IncomingMessage,
  res: ServerResponse,
  options: Required<DaemonProxyOptions>,
)

Source from the content-addressed store, hash-verified

44}
45
46async function handleProxyRequest(
47 req: IncomingMessage,
48 res: ServerResponse,
49 options: Required<DaemonProxyOptions>,
50): Promise<void> {
51 const route = resolveProxyRoute(req.url ?? '/');
52 if (req.method === 'GET' && route === '/health') {
53 await sendProxyHealth(res, options);
54 return;
55 }
56
57 if (!isSupportedDaemonRoute(route, req.method)) {
58 res.statusCode = 404;
59 res.end('Not found');
60 return;
61 }
62
63 let rpcBody: string | undefined;
64 if (route === '/rpc') {
65 rpcBody = (
66 await readNodeHttpRequestBody(
67 req,
68 options.maxRpcBodyBytes,
69 'Proxy request body is too large.',
70 )
71 ).toString('utf8');
72 }
73
74 if (!isAuthorized(req, options.clientToken, rpcBody)) {
75 sendUnauthorized(res, route, readJsonRpcId(rpcBody));
76 return;
77 }
78
79 await forwardProxyRequest({ req, res, route, options, rpcBody });
80}
81
82async function sendProxyHealth(res: ServerResponse, options: Required<DaemonProxyOptions>) {
83 const upstream = await readUpstreamHealth(options);

Callers 1

createDaemonProxyServerFunction · 0.85

Calls 8

readNodeHttpRequestBodyFunction · 0.90
resolveProxyRouteFunction · 0.85
sendProxyHealthFunction · 0.85
isSupportedDaemonRouteFunction · 0.85
isAuthorizedFunction · 0.85
sendUnauthorizedFunction · 0.85
readJsonRpcIdFunction · 0.85
forwardProxyRequestFunction · 0.85

Tested by

no test coverage detected