JavaScript & TypeScript
Browser IMG patterns with publishable tokens, SSR fetch helpers in Node/Workers, openapi-typescript codegen, and Next.js cache alignment.
Browser <img> (publishable)
const src =
`https://img.logorouter.com/${encodeURIComponent(domain)}` +
`?size=${size}&format=webp&token=${encodeURIComponent(pubKey)}`;
return <img src={src} alt={`${domain} logo`} width={64} height={64} loading="lazy" />;Secrets never reach the DOM — hydrate publishable URLs from environment-safe props or Clerk-protected loaders.
Need palette JSON in the browser? Ship precomputed hues via your backend calling /docs/api/colors.
Node / Workers fetch
export async function loadLogo(domain: string, secret: string) {
const res = await fetch(
`https://api.logorouter.com/api/${encodeURIComponent(domain)}?size=256&format=png`,
{
headers: {
Authorization: `Bearer ${secret}`,
Accept: "image/png",
},
cache: "default",
}
);
if (!res.ok) {
const ct = res.headers.get("content-type") ?? "";
throw new Error(
ct.includes("application/json") || ct.includes("problem+json")
? JSON.stringify(await res.json())
: await res.text()
);
}
return new Uint8Array(await res.arrayBuffer());
}Type tooling (openapi-typescript)
pnpm dlx openapi-typescript https://api.logorouter.com/api/openapi.json -o ./src/generated/logorouter.tsRegenerate alongside dependency bumps — schemas grow additively; diff generated files inside CI reviews.
Operational headers (x-lr-*) remain intentionally undocumented in schemas — log them externally.
Next.js App Router caches
Leverage fetch caching semantics responsibly:
await fetch(apiUrl, { next: { revalidate: 60 * 30, tags: [`logo:${domain}`] } });Bytes already carry CDN-friendly TTL headers — marry them with ISR/partial prerender plans so dashboards stay fast without starving cold paths.