deno.land / x / lume@v2.1.4 / middlewares / cache_busting.ts

cache_busting.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import type { Middleware } from "../core/server.ts";
export interface Options { regex: RegExp; replacement: string;}
export const defaults: Options = { regex: /^\/v[\d]+\//, replacement: "/",};
/** Implements cache busting */export default function cacheBusting(options?: Partial<Options>): Middleware { const { regex, replacement } = { ...defaults, ...options };
return async (request, next) => { const url = new URL(request.url); const { pathname } = url;
if (pathname.match(regex)) { url.pathname = pathname.replace(regex, replacement); request = new Request(url.href, { ...request, }); }
return await next(request); };}
lume

Version Info

Tagged at
a month ago