forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
29 lines (22 loc) · 677 Bytes
/
proxy.ts
File metadata and controls
29 lines (22 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { getLLMText, source } from "@/lib/source/docs";
import type { NextRequest } from "next/server";
export async function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
if (!pathname.endsWith(".md")) {
return;
}
const slug = pathname.slice(0, -3).split("/").filter(Boolean).slice(1);
const page = source.getPage(slug);
if (!page) {
return new Response("Not Found", { status: 404 });
}
const markdown = await getLLMText(page);
return new Response(markdown, {
headers: {
"Content-Type": "text/markdown; charset=utf-8",
},
});
}
export const config = {
matcher: ["/docs/:path*", "/docs", "/docs.md"],
};