UNPKG

@universal-middleware/compress

Version:
54 lines (50 loc) 1.83 kB
import { bindUniversal, universalSymbol, contextSymbol, getAdapterRuntime } from './chunk-A5W3PKM7.js'; import { middleware_default } from './chunk-OE4YTAMF.js'; // ../adapter-hattip/dist/index.js 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: ignored env: context.platform?.env, // biome-ignore lint/suspicious/noExplicitAny: ignored ctx: context.platform?.context, // biome-ignore lint/suspicious/noExplicitAny: ignored req: context.platform?.request, // biome-ignore lint/suspicious/noExplicitAny: ignored res: context.platform?.response }, context.request ); } // virtual:universal-middleware:virtual:universal-middleware:hattip:middleware:src/middleware.ts var middleware_default2 = createMiddleware(middleware_default); export { middleware_default2 as default };