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;
};
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v10
May 24, 2024