|
1 | 1 | import { StreamableHTTPTransport } from "@hono/mcp" |
2 | 2 | import { Hono } from "hono" |
| 3 | +import { accepts } from "hono/accepts" |
3 | 4 | import { cache } from "hono/cache" |
4 | 5 | import { cors } from "hono/cors" |
5 | 6 | import { HTTPException } from "hono/http-exception" |
@@ -76,6 +77,33 @@ app.all("/mcp", async (c) => { |
76 | 77 | return transport.handleRequest(c) |
77 | 78 | }) |
78 | 79 |
|
| 80 | +app.get("/", async (c) => { |
| 81 | + const accepted = accepts(c, { |
| 82 | + header: "Accept", |
| 83 | + supports: ["text/markdown", "text/html"], |
| 84 | + default: "text/html", |
| 85 | + }) |
| 86 | + |
| 87 | + if (accepted === "text/markdown") { |
| 88 | + const llmsUrl = new URL("/llms.txt", c.req.url) |
| 89 | + const llmsResponse = await c.env.ASSETS.fetch(new Request(llmsUrl.toString())) |
| 90 | + |
| 91 | + if (!llmsResponse.ok) { |
| 92 | + throw new HTTPException(500, { |
| 93 | + message: "Failed to load llms.txt", |
| 94 | + }) |
| 95 | + } |
| 96 | + |
| 97 | + const markdown = await llmsResponse.text() |
| 98 | + return c.text(markdown, 200, { |
| 99 | + "Content-Type": "text/markdown; charset=utf-8", |
| 100 | + "Cache-Control": "public, max-age=300, s-maxage=600", |
| 101 | + }) |
| 102 | + } |
| 103 | + |
| 104 | + return c.env.ASSETS.fetch(c.req.raw) |
| 105 | +}) |
| 106 | + |
79 | 107 | app.get("/bot", (c) => c.redirect("/#bot", 302)) |
80 | 108 |
|
81 | 109 | app.get("/search", async (c) => { |
|
0 commit comments