1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import valTownBadge from "https://esm.town/v/jxnblk/valTownBadge02";
export default function badgeMiddleware(handler, url: string) {
return async function(req: Request): Promise<Response> {
if (req.method !== "GET") return await handler(req);
let res = await handler(req);
if (res.headers.get("Content-Type")?.includes("text/html")) {
let body = await res.text();
const badge = valTownBadge(url);
body += `<div style="position:fixed;right:0;bottom:0;margin:8px">${badge}</div>`;
res = new Response(body, res);
}
return res;
};
}