Readme

How to use:

import wrapper from "https://esm.town/v/substrate/substrateBadgeMiddleware"; async function handler(req: Request): Promise<Response> { const html = ` <h1>Hello, world</h1> `; return new Response(html, { headers: { "Content-Type": "text/html; charset=utf-8", }, }); } export default wrapper(handler, import.meta.url);

reference: https://www.val.town/v/jxnblk/valTownBadge

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import valTownBadge from "https://esm.town/v/substrate/substrateBadge";
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!
July 10, 2024