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

Function createDaemonHttpServer

src/daemon/server/http-server.ts:513–746  ·  view source on GitHub ↗
(options: {
  handleRequest: DaemonInvokeFn;
  token?: string;
  retainArtifacts?: boolean;
})

Source from the content-addressed store, hash-verified

511}
512
513export async function createDaemonHttpServer(options: {
514 handleRequest: DaemonInvokeFn;
515 token?: string;
516 retainArtifacts?: boolean;
517}): Promise<http.Server> {
518 const authHook = await loadHttpAuthHook();
519 const { handleRequest, token, retainArtifacts = false } = options;
520 return http.createServer((req, res) => {
521 if (req.method === 'GET' && req.url === '/health') {
522 res.statusCode = 200;
523 res.setHeader('content-type', 'application/json');
524 res.end(JSON.stringify(buildDaemonHealthPayload('agent-device-daemon')));
525 return;
526 }
527
528 if (
529 tryHandleUploadHttpRoute({
530 req,
531 res,
532 token: resolveToken({}, req.headers),
533 authorize: async (request) =>
534 await authorizeAuxiliaryHttpRequest({
535 req: request.req,
536 res: request.res,
537 authHook,
538 expectedToken: token,
539 daemonRequest: request.daemonRequest,
540 }),
541 })
542 ) {
543 return;
544 }
545
546 if (
547 tryHandleDownloadableArtifactHttpRoute({
548 req,
549 res,
550 retainArtifacts,
551 authorize: async (request) =>
552 await authorizeAuxiliaryHttpRequest({
553 req: request.req,
554 res: request.res,
555 authHook,
556 expectedToken: token,
557 daemonRequest: request.daemonRequest,
558 }),
559 })
560 ) {
561 return;
562 }
563
564 if (req.method !== 'POST' || req.url !== '/rpc') {
565 res.statusCode = 404;
566 res.end('Not found');
567 return;
568 }
569
570 let body = '';

Callers 4

openDaemonServersFunction · 0.90
withCommandRpcServerFunction · 0.90

Calls 15

buildDaemonHealthPayloadFunction · 0.90
tryHandleUploadHttpRouteFunction · 0.90
resolveRequestTrackingIdFunction · 0.90
registerRequestAbortFunction · 0.90
withRequestProgressSinkFunction · 0.90
normalizeErrorFunction · 0.90
clearRequestCanceledFunction · 0.90
loadHttpAuthHookFunction · 0.85
resolveTokenFunction · 0.85

Tested by 1

withCommandRpcServerFunction · 0.72