UNPKG

@universal-middleware/compress

Version:
54 lines (50 loc) 1.87 kB
import { bindUniversal, universalSymbol, getAdapterRuntime } from './chunk-MMHRYIMR.js'; import { middleware_default } from './chunk-SBN5FRVL.js'; // ../adapter-hattip/dist/index.js var contextSymbol = Symbol.for("unContext"); function createMiddleware(middlewareFactory) { return (...args) => { const middleware = middlewareFactory(...args); return bindUniversal(middleware, async function universalMiddlewareHattip(context) { const ctx = initContext(context); const response = await this[universalSymbol](context.request, ctx, getRuntime(context)); if (typeof response === "function") { const res = await context.next(); const actualRes = await response(res); return actualRes ?? res; } if (response !== null && typeof response === "object") { if (response instanceof Response) { return response; } context[contextSymbol] = response; } }); }; } function initContext(context) { context[contextSymbol] ??= {}; return context[contextSymbol]; } function getRuntime(context) { return getAdapterRuntime( "hattip", { params: "params" in context ? context.params : void 0, hattip: context }, { // biome-ignore lint/suspicious/noExplicitAny: <explanation> env: context.platform?.env, // biome-ignore lint/suspicious/noExplicitAny: <explanation> ctx: context.platform?.context, // biome-ignore lint/suspicious/noExplicitAny: <explanation> req: context.platform?.request, // biome-ignore lint/suspicious/noExplicitAny: <explanation> res: context.platform?.response } ); } // virtual:universal-middleware:virtual:universal-middleware:hattip:middleware:src/middleware.ts var middleware_default2 = createMiddleware(middleware_default); export { middleware_default2 as default };