Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.3 kB ยท 42 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243export interface DetectMarkdownResult { wantsMarkdown: boolean; source: "suffix" | "header" | null; /** Pathname with a trailing `.md` stripped, so `resolveRoute` runs unchanged. */ pathname: string;}
function acceptsMarkdown(accept: string | null): boolean { if (!accept) return false; // Match the media type as a whole token, tolerating params/q-values and casing. return accept .toLowerCase() .split(",") .some((part) => part.trim().split(";")[0].trim() === "text/markdown");}
/** * Proxy-side detection of a markdown request. The `.md` suffix wins over the * Accept header so a `.md` URL keeps the cache-safe suffix policy. */export function detectMarkdown(input: { pathname: string; accept: string | null;}): DetectMarkdownResult { const { pathname, accept } = input;
if (pathname.endsWith(".md")) { const stripped = pathname.slice(0, -".md".length); // `/.md` (root) โ `/`; otherwise keep the stripped path. return { wantsMarkdown: true, source: "suffix", pathname: stripped === "" ? "/" : stripped, }; }
if (acceptsMarkdown(accept)) { return { wantsMarkdown: true, source: "header", pathname }; }
return { wantsMarkdown: false, source: null, pathname };}