Skip to content

app: metadataBase is hardcoded to localhost, breaking all social previews in production #1

Description

@joelpeace48-cell

Problem

app/layout.tsx sets:

export const metadata: Metadata = {
  metadataBase: new URL("http://localhost:3000"),
  ...
}

Next.js resolves every relative Open Graph and Twitter image URL against
metadataBase. Deployed, this emits absolute URLs pointing at
http://localhost:3000 — so app/opengraph-image.tsx and
app/twitter-image.tsx (both of which exist and render) resolve to a host the
crawler cannot reach.

Every link shared to Twitter, LinkedIn, Slack, or Discord renders without a
preview card. For a project whose reach depends on grant reviewers and
hackathon judges following a link, this is a visible own-goal.

What to do

  • Drive metadataBase from an environment variable
    (NEXT_PUBLIC_SITE_URL), falling back to the Vercel-provided
    VERCEL_URL for previews and to localhost only in development.
  • Add openGraph.url and a canonical URL.
  • Verify with a real crawler once deployed.

Acceptance criteria

  • metadataBase resolved from the environment per deployment
  • OG and Twitter image URLs absolute and reachable in production
  • Canonical URL set
  • Validated against a card-preview tool after deploy

Notes

Also worth setting metadata.title.template per route so shared deep links
carry a meaningful title rather than the site default.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSThird CampaignCampaign: Third Campaignarea:appRoutes (app/)difficulty:easySelf-contained; no deep domain context neededpriority:criticalBlocks everything else; security or build-breakingtype:bugIncorrect behaviour

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions