import { resolve } from "node:path"; import { badgeApi, lanyardConfig } from "@config/environment"; import { file } from "bun"; const routeDef: RouteDef = { method: "GET", accepts: "*/*", returns: "text/html", }; async function handler(request: ExtendedRequest): Promise { const { id } = request.params; const instance = lanyardConfig.instance .replace(/^https?:\/\//, "") .replace(/\/$/, ""); const path = resolve("src", "views", "index.html"); const bunFile = file(path); const html = new HTMLRewriter() .on("head", { element(head) { head.setAttribute("data-user-id", id || lanyardConfig.userId); head.setAttribute("data-instance-uri", instance); head.setAttribute("data-badge-url", badgeApi || ""); }, }) .transform(await bunFile.text()); return new Response(html, { headers: { "Content-Type": "text/html", }, }); } export { handler, routeDef };