Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

feat: add Context7 Ask discovery

Amruth Pillai5c9f0e988d43
diff --git a/apps/server/src/http/app.test.ts b/apps/server/src/http/app.test.ts
index 8addc95bd..191d9c181 100644
--- a/apps/server/src/http/app.test.ts
+++ b/apps/server/src/http/app.test.ts
@@ -120,6 +120,13 @@ beforeEach(() => {
});
describe("createApp", () => {
+ it("serves /index.html through the shared HTML response before static files", async () => {
+ const { createApp } = await import("./app");
+ const response = await createApp().request("/index.html");
+ expect(await response.text()).toBe("web");
+ expect(mocks.serveWebDistStatic).not.toHaveBeenCalled();
+ });
+
// The first case pays for the cold import of the whole app, which takes seconds under a parallel run.
it.each([
["127.0.0.1", "127.0.0.1", "198.51.100.1", "198.51.100.1"],
diff --git a/apps/server/src/http/app.ts b/apps/server/src/http/app.ts
index f1665d2ba..eceeda6cf 100644
--- a/apps/server/src/http/app.ts
+++ b/apps/server/src/http/app.ts
@@ -151,7 +151,7 @@ export function createApp(options: AppOptions = {}) {
// 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, options.readWebFile));
+ app.on(["GET", "HEAD"], ["/", "/index.html"], (c) => handleWebApp(c.req.raw, options.readWebFile));
if (options.serveStatic !== false && serveWebDistStatic) app.use("/*", serveWebDistStatic);
app.on(["GET", "HEAD"], "/*", (c) => handleWebApp(c.req.raw, options.readWebFile));
diff --git a/apps/server/src/static/seo.test.ts b/apps/server/src/static/seo.test.ts
index ef8b85675..53b892360 100644
--- a/apps/server/src/static/seo.test.ts
+++ b/apps/server/src/static/seo.test.ts
@@ -2,7 +2,18 @@ import { describe, expect, it, vi } from "vite-plus/test";
vi.mock("@reactive-resume/env/server", () => ({ env: { APP_URL: "https://rxresu.me/" } }));
-const { handleSitemap } = await import("./seo");
+const { handleSitemap, handleLlms } = await import("./seo");
+
+it("publishes Context7 Ask after the llms title and summary", async () => {
+ const text = await handleLlms().text();
+ expect(text).toMatch(
+ /^# Reactive Resume\n\n> [^\n]+\n\n## Search\n\nThis site has a search endpoint: https:\/\/context7.com\/api\/v2\/ask\?siteKey=ask_b3fd9335a63f1b21b1a814ac&query=<URL-encoded question>\./,
+ );
+ expect(text).toContain(
+ "It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.\n\n## Product",
+ );
+ expect(await handleLlms({ head: true }).text()).toBe("");
+});
describe("localized sitemap", () => {
it("gives every localized public page its own entry with reciprocal alternates", async () => {
diff --git a/apps/server/src/static/seo.ts b/apps/server/src/static/seo.ts
index c645343e6..b0c3bb620 100644
--- a/apps/server/src/static/seo.ts
+++ b/apps/server/src/static/seo.ts
@@ -3,6 +3,8 @@ import { templateSchema } from "@reactive-resume/schema/templates";
import { getLocaleAlternates } from "@reactive-resume/utils/locale";
const DOCS_URL = "https://docs.rxresu.me";
+export const CONTEXT7_ASK_URL = "https://context7.com/api/v2/ask?siteKey=ask_b3fd9335a63f1b21b1a814ac";
+export const CONTEXT7_ASK_DESCRIPTION = `This site has a search endpoint: ${CONTEXT7_ASK_URL}&query=<URL-encoded question>. It returns documentation that answers the question, with a source link for each part. No API key is needed. If nothing matches, it says so.`;
type StaticSeoOptions = {
head?: boolean;
@@ -80,6 +82,10 @@ export function handleLlms(options?: StaticSeoOptions) {
"",
`> Reactive Resume is a free and open-source resume builder. Write a resume in an editor beside a live page, pick one of ${templateSchema.options.length} templates, check that applicant tracking systems can read it, tailor it to a job posting, and share it at a public link or download it. No ads, no tracking, no paid tier; it is funded by donations and released under the MIT License.`,
"",
+ "## Search",
+ "",
+ CONTEXT7_ASK_DESCRIPTION,
+ "",
"## Product",
"",
`- [Homepage](${baseUrl}/): what Reactive Resume does, with answers to common questions.`,
diff --git a/apps/server/src/static/web.test.ts b/apps/server/src/static/web.test.ts
index b415da70c..838a62ca1 100644
--- a/apps/server/src/static/web.test.ts
+++ b/apps/server/src/static/web.test.ts
@@ -40,6 +40,29 @@ describe("web app fallback classification", () => {
mocks.getPublicResumeSocialMeta.mockResolvedValue(null);
});
+ it.each(["/", "/?locale=de-DE", "/ats-checker", "/resume-templates", "/dashboard", "/alice/resume", "/index.html"])(
+ "advertises Context7 Ask in server-rendered %s and its HEAD response",
+ async (path) => {
+ vi.mocked(fs.readFile).mockResolvedValue('<html><head></head><body><div id="app"></div></body></html>');
+ const response = await handleWebApp(new Request(`https://rxresu.me${path}`));
+ const html = await response.text();
+ expect(html).toContain('<meta name="context7-site-verification" content="ask_b3fd9335a63f1b21b1a814ac"></head>');
+ expect(html).toContain('<body><blockquote data-context7-ask="true" aria-hidden="true" class="sr-only">');
+ expect(html).toContain("<h2>Search</h2><p>Page index: https://rxresu.me/llms.txt.</p>");
+ expect(html).toContain(
+ "https://context7.com/api/v2/ask?siteKey=ask_b3fd9335a63f1b21b1a814ac&amp;query=&lt;URL-encoded question&gt;",
+ );
+ expect(html).toContain('</blockquote><div id="app"></div>');
+ expect(html).not.toContain("Add .md");
+ const link =
+ '<https://context7.com/api/v2/ask?siteKey=ask_b3fd9335a63f1b21b1a814ac>; rel="search"; type="text/plain"; title="Search rxresu.me"';
+ expect(response.headers.get("Link")).toBe(link);
+ const head = await handleWebApp(new Request(`https://rxresu.me${path}`, { method: "HEAD" }));
+ expect(head.headers.get("Link")).toBe(link);
+ expect(await head.text()).toBe("");
+ },
+ );
+
it("injects canonical metadata and structured data into tracking-parameter root requests only", async () => {
vi.mocked(fs.readFile).mockResolvedValue(`
<!doctype html>
diff --git a/apps/server/src/static/web.ts b/apps/server/src/static/web.ts
index 40e17682a..4dfb22705 100644
--- a/apps/server/src/static/web.ts
+++ b/apps/server/src/static/web.ts
@@ -7,6 +7,7 @@ import { serveStatic } from "@hono/node-server/serve-static";
import { env } from "@reactive-resume/env/server";
import { templateSchema } from "@reactive-resume/schema/templates";
import { defaultLocale, getLocaleAlternates, isLocale, localizedUrl } from "@reactive-resume/utils/locale";
+import { CONTEXT7_ASK_DESCRIPTION, CONTEXT7_ASK_URL } from "./seo";
function resolveWebDistPath() {
const candidates = [
@@ -101,6 +102,7 @@ function contentSecurityPolicy(html = "") {
}
const BASE_SECURITY_HEADERS = {
+ Link: `<${CONTEXT7_ASK_URL}>; rel="search"; type="text/plain"; title="Search rxresu.me"`,
"X-Frame-Options": "DENY",
"X-Content-Type-Options": "nosniff",
"Referrer-Policy": "strict-origin-when-cross-origin",
@@ -112,7 +114,12 @@ const BASE_SECURITY_HEADERS = {
* any resume-derived markup goes in, so text that slipped past escaping could never allow itself.
*/
function htmlResponse(html: string, headers: Record<string, string>, template = html) {
- return new Response(html, { headers: { ...headers, "Content-Security-Policy": contentSecurityPolicy(template) } });
+ const verification = new URL(CONTEXT7_ASK_URL).searchParams.get("siteKey") ?? "";
+ const note = `<blockquote data-context7-ask="true" aria-hidden="true" class="sr-only"><h2>Search</h2><p>Page index: https://rxresu.me/llms.txt.</p><p>${escapeAttribute(CONTEXT7_ASK_DESCRIPTION)}</p></blockquote>`;
+ const body = html
+ .replace("</head>", () => `<meta name="context7-site-verification" content="${verification}"></head>`)
+ .replace(/<body\b[^>]*>/i, (tag) => `${tag}${note}`);
+ return new Response(body, { headers: { ...headers, "Content-Security-Policy": contentSecurityPolicy(template) } });
}
const githubUrl = "https://github.com/reactive-resume/reactive-resume";
@@ -421,7 +428,8 @@ export type ReadWebFile = (path: string) => Promise<string>;
export async function handleWebApp(request: Request, readFile: ReadWebFile = (path) => fs.readFile(path, "utf-8")) {
const isHead = request.method === "HEAD";
- const pathname = new URL(request.url).pathname;
+ const requestedPath = new URL(request.url).pathname;
+ const pathname = requestedPath === "/index.html" ? "/" : requestedPath;
if (!isNoindexShellPath(pathname) && isAssetPath(pathname)) {
return new Response(isHead ? null : "Not Found", { status: 404 });