All checks were successful
Code quality checks / biome (push) Successful in 8s
lazy image load
37 lines
910 B
TypeScript
37 lines
910 B
TypeScript
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<Response> {
|
|
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 };
|