import{Hono as f}from"hono";import{TrieRouter as g}from"hono/router/trie-router";import{Logger as d}from"../tools/notifiers/logger.js";import{importApiRoutesHandler as m}from"./import-api-routes-handlers.js";import{enhanceContext as w}from"./helpers/enhance-context.js";import{getBodyWithSizeCheck as y}from"./helpers/get-body-with-size-check.js";import{setupLogger as p}from"./helpers/setup-logger.js";import{telemetry as s}from"../telemetry/index.js";const o=new d;o.patchConsole();async function C(e){s.initialize(),p(o,e.loggerStickyState,e.requestHandlerId);const n=new f({router:new g}),{requestHandlers:u}=await m(e.serverOutDir),a=u[e.requestHandlerId],c=(await a()).default;n.all(e.slug,async t=>{const r=await c(t.req.raw,w(t,e.ctxData,s),e.staticData);return r instanceof Response?r:typeof r=="string"?t.text(r):t.json(r)}),n.onError((t,r)=>{if(o.error(`[${e.requestHandlerId}] ${t.message} ${t.stack}`),t instanceof SyntaxError)return r.text(t.message,500);throw t});const i=await n.request(e.req.url,e.req),l=await y(i,e.maxResponseSizeMB);return{status:i.status,headers:Object.fromEntries(i.headers.entries()),body:l,loggerStickyState:o.getStickyState()}}export{C as executeApiRoute};
