mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 23:32:19 +10:00
fix(server): use public URL for homepage metadata
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
const mocks = vi.hoisted(() => ({
|
||||||
|
env: { APP_URL: "https://rxresu.me" },
|
||||||
serveStatic: vi.fn((_options?: unknown) => vi.fn()),
|
serveStatic: vi.fn((_options?: unknown) => vi.fn()),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -19,6 +20,10 @@ vi.mock("@hono/node-server/serve-static", () => ({
|
|||||||
serveStatic: mocks.serveStatic,
|
serveStatic: mocks.serveStatic,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock("@reactive-resume/env/server", () => ({
|
||||||
|
env: mocks.env,
|
||||||
|
}));
|
||||||
|
|
||||||
type StaticOptions = {
|
type StaticOptions = {
|
||||||
onFound?: (
|
onFound?: (
|
||||||
path: string,
|
path: string,
|
||||||
@@ -62,15 +67,16 @@ describe("web app fallback classification", () => {
|
|||||||
</html>
|
</html>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const response = await handleWebApp(new Request("https://example.com/?utm_source=search"));
|
const response = await handleWebApp(new Request("http://server.internal/?utm_source=search"));
|
||||||
const html = await response.text();
|
const html = await response.text();
|
||||||
|
|
||||||
expect(html).toContain('<link rel="canonical" href="https://example.com/">');
|
expect(html).toContain('<link rel="canonical" href="https://rxresu.me/">');
|
||||||
expect(html).toContain('<link rel="preload" href="/videos/timelapse-v1.webp" as="image" fetchpriority="high">');
|
expect(html).toContain('<link rel="preload" href="/videos/timelapse-v1.webp" as="image" fetchpriority="high">');
|
||||||
expect(html).toContain('<meta property="og:url" content="https://example.com/">');
|
expect(html).toContain('<meta property="og:url" content="https://rxresu.me/">');
|
||||||
expect(html).toContain('<meta property="og:image" content="https://example.com/opengraph/banner.jpg">');
|
expect(html).toContain('<meta property="og:image" content="https://rxresu.me/opengraph/banner.jpg">');
|
||||||
expect(html).toContain('id="reactive-resume-structured-data"');
|
expect(html).toContain('id="reactive-resume-structured-data"');
|
||||||
expect(html).toContain('"@type":["SoftwareApplication","WebApplication"]');
|
expect(html).toContain('"@type":["SoftwareApplication","WebApplication"]');
|
||||||
|
expect(html).toContain('"url":"https://rxresu.me/"');
|
||||||
expect(html).not.toContain("utm_source");
|
expect(html).not.toContain("utm_source");
|
||||||
|
|
||||||
const dashboardResponse = await handleWebApp(new Request("https://example.com/dashboard"));
|
const dashboardResponse = await handleWebApp(new Request("https://example.com/dashboard"));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
import { serveStatic } from "@hono/node-server/serve-static";
|
import { serveStatic } from "@hono/node-server/serve-static";
|
||||||
|
import { env } from "@reactive-resume/env/server";
|
||||||
|
|
||||||
function resolveWebDistPath() {
|
function resolveWebDistPath() {
|
||||||
const candidates = [
|
const candidates = [
|
||||||
@@ -193,8 +194,7 @@ function notFoundResponse(options: { head?: boolean; noindex?: boolean } = {}) {
|
|||||||
// ponytail: GET and HEAD share the same routing logic; method determines body presence
|
// ponytail: GET and HEAD share the same routing logic; method determines body presence
|
||||||
export async function handleWebApp(request: Request) {
|
export async function handleWebApp(request: Request) {
|
||||||
const isHead = request.method === "HEAD";
|
const isHead = request.method === "HEAD";
|
||||||
const requestUrl = new URL(request.url);
|
const pathname = new URL(request.url).pathname;
|
||||||
const pathname = requestUrl.pathname;
|
|
||||||
|
|
||||||
if (!isNoindexShellPath(pathname) && isAssetPath(pathname)) {
|
if (!isNoindexShellPath(pathname) && isAssetPath(pathname)) {
|
||||||
return new Response(isHead ? null : "Not Found", { status: 404 });
|
return new Response(isHead ? null : "Not Found", { status: 404 });
|
||||||
@@ -206,7 +206,7 @@ export async function handleWebApp(request: Request) {
|
|||||||
if (isHead) return new Response(null, { status: 200, headers });
|
if (isHead) return new Response(null, { status: 200, headers });
|
||||||
|
|
||||||
const html = await fs.readFile(indexHtmlPath, "utf-8");
|
const html = await fs.readFile(indexHtmlPath, "utf-8");
|
||||||
const canonicalUrl = new URL("/", requestUrl.origin).toString();
|
const canonicalUrl = new URL("/", env.APP_URL).toString();
|
||||||
const responseHtml = pathname === "/" ? html.replace("</head>", `${createRootSeoMarkup(canonicalUrl)}</head>`) : html;
|
const responseHtml = pathname === "/" ? html.replace("</head>", `${createRootSeoMarkup(canonicalUrl)}</head>`) : html;
|
||||||
|
|
||||||
return new Response(responseHtml, { headers });
|
return new Response(responseHtml, { headers });
|
||||||
|
|||||||
Reference in New Issue
Block a user