@worker-tools/middleware
Version:
A suite of standalone HTTP server middlewares for Worker Runtimes.
10 lines • 550 B
JavaScript
import { format } from '@tusbar/cache-control';
const SECOND = { unit: 'second', relativeTo: '1970-01-01' };
const isDuration = (x) => (x === null || x === void 0 ? void 0 : x[Symbol.toStringTag]) === 'Temporal.Duration';
export const caching = (options = {}) => async (ax) => {
const x = await ax;
const opts = Object.fromEntries(Object.entries(options).map(([k, v]) => [k, isDuration(v) ? v.total(SECOND) : v]));
x.effects.push(res => res.headers.set('Cache-Control', format(opts)));
return x;
};
//# sourceMappingURL=caching.js.map