nitrojs / nitrojs/nitro

Support canonical URL

Open
#2,052 6 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

ref https://github.com/nuxt/nuxt/issues/24813

Today, we expose useRequestURL() utility to access the current request URL however it can be tricky in two situations:

  • In SSG, we cannot access the desired URL
  • In runtime, sometimes, we need a canonical URL different from the incoming request
  • In cached event handlers, we don't have access to incoming headers without opting more headers to varies (which can also lead to cache leaks)
  • When we require a full URL for generating content there is no one standard way to depend on
  • With fetch(/path) we need a default host (instead of assuming localhost)

Proposal:

  • Support app.canonicalURL in runtimeConfig for env support + app config for dynamic behavior support (prefer app)
  • Use canonical URL as default fallback for useRequestURL()
  • Introduce new useCanonicalURL() (suggested by @Atinux) that falls back to useRequestURL() if the user hasn't configured a canonical URL and fails for SSG if not provided

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing useRequestURL() utility and the runtimeConfig and app config handling referenced in the proposal. Trace how URLs are resolved in SSG, runtime requests, cached event handlers, and fetch(/path). Done means app.canonicalURL and a useCanonicalURL() fallback are supported, with the stated SSG failure behavior when no canonical URL is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.