mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-23 23:02:17 +10:00
fix(seo): serve the root request through the web app handler
The static middleware was mounted ahead of the web app fallback, and Hono's serveStatic resolves "/" to the directory and returns dist/index.html verbatim. handleWebApp never ran for the root route, so the OpenGraph, Twitter, canonical and JSON-LD markup it injects was missing in production - fetching https://rxresu.me/ as Twitterbot returned zero og: tags. Route "/" explicitly before the static middleware so the injection runs.
This commit is contained in:
@@ -192,4 +192,16 @@ describe("createApp", () => {
|
|||||||
expect(mocks.serveWebDistStatic).not.toHaveBeenCalled();
|
expect(mocks.serveWebDistStatic).not.toHaveBeenCalled();
|
||||||
expect(mocks.handleWebApp).not.toHaveBeenCalled();
|
expect(mocks.handleWebApp).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each(["GET", "HEAD"])("routes %s / to the web app handler so SEO markup is injected", async (method) => {
|
||||||
|
const { createApp } = await import("./app");
|
||||||
|
const app = createApp();
|
||||||
|
const request = new Request("http://localhost:3001/", { method });
|
||||||
|
|
||||||
|
const response = await app.fetch(request);
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(mocks.handleWebApp).toHaveBeenCalledWith(request);
|
||||||
|
expect(mocks.serveWebDistStatic).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ export function createApp() {
|
|||||||
app.on(["GET", "HEAD"], "/sitemap.xml", (c) => handleSitemap({ head: c.req.method === "HEAD" }));
|
app.on(["GET", "HEAD"], "/sitemap.xml", (c) => handleSitemap({ head: c.req.method === "HEAD" }));
|
||||||
app.on(["GET", "HEAD"], "/llms.txt", (c) => handleLlms({ head: c.req.method === "HEAD" }));
|
app.on(["GET", "HEAD"], "/llms.txt", (c) => handleLlms({ head: c.req.method === "HEAD" }));
|
||||||
|
|
||||||
|
// Must precede the static middleware: serveStatic resolves "/" to dist/index.html and would
|
||||||
|
// return it verbatim, skipping the OpenGraph/Twitter/canonical/JSON-LD injection in handleWebApp.
|
||||||
|
app.on(["GET", "HEAD"], "/", (c) => handleWebApp(c.req.raw));
|
||||||
app.use("/*", serveWebDistStatic);
|
app.use("/*", serveWebDistStatic);
|
||||||
app.on(["GET", "HEAD"], "/*", (c) => handleWebApp(c.req.raw));
|
app.on(["GET", "HEAD"], "/*", (c) => handleWebApp(c.req.raw));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user