UNPKG

elysia

Version:

Ergonomic Framework for Human

21 lines (20 loc) 867 B
import { isHTMLBundle } from "./index.mjs"; import { mapResponse } from "./handler.mjs"; const createNativeStaticHandler = (handle, hooks, set) => { if (typeof handle == "function" || handle instanceof Blob) return; if (isHTMLBundle(handle)) return () => handle; const response = mapResponse( handle, set ?? { headers: {} } ); if (!hooks.parse?.length && !hooks.transform?.length && !hooks.beforeHandle?.length && !hooks.afterHandle?.length) return response instanceof Promise ? response.then((response2) => { if (response2) return response2.headers.has("content-type") || response2.headers.append("content-type", "text/plain"), response2.clone(); }) : (response.headers.has("content-type") || response.headers.append("content-type", "text/plain"), () => response.clone()); }; export { createNativeStaticHandler };