profilePage/src/routes/[id].ts
creations 2ee5f0512e
All checks were successful
Code quality checks / biome (push) Successful in 8s
move to raw html, make readme use buns html rewrite and always set to
lazy image load
2025-04-26 11:10:31 -04:00

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 };