Skip to content

✨ feat(redirect): add update command and normalise FQDN handling - #1

Merged
kud merged 1 commit into
mainfrom
feat/redirect-update-normalise-fqdn
Aug 1, 2026
Merged

kud merged 1 commit into
mainfrom
feat/redirect-update-normalise-fqdn

Conversation

@kud

@kud kud commented Aug 1, 2026

Copy link
Copy Markdown
Owner

πŸ“„ Description

New: gandi redirect update <domain> <source> [target]

Updates a web redirect in place via PATCH /v5/domain/domains/{domain}/webredirs/{host}, instead of the old delete-then-add dance. Flags: -t/--type, -p/--protocol, --override/--no-override. Only the fields you actually supply are sent, so anything you don't touch is preserved β€” running it with no target and no flags errors with "Nothing to update" rather than firing an empty PATCH.

This matters because delete-then-add was the only way to change a redirect's target before, and that discards the Gandi-issued TLS certificate and resets protocol. Verified live: updating trakt.kud.io preserved protocol: https untouched.

Known limit, not a bug: Gandi's PATCH has no host field, so update can't move a redirect to a different subdomain β€” that still needs delete + add.

Fix: host handling was wrong in three places

Gandi identifies a redirect by its fully-qualified source host β€” in the list response, in the {host} path segment, and in the POST body. The CLI assumed a bare label instead:

  • redirect list printed a doubled suffix (500px.kud.io.kud.io) β€” now prints 500px.kud.io.
  • redirect delete built its path as /webredirs/{label}, which the API rejects with 400 β€” now sends the FQDN.
  • redirect add's success line had the same doubling.

New exported helper toRedirectHost(domain, host) normalises either spelling to the FQDN and is idempotent, so scripts already passing a bare label keep working.

⚠ Behaviour change: redirect list output and redirect delete's request path both change as a result of the fix above. Both are bug fixes, but anyone scripting against the old output would notice.

Tests

New describe blocks in src/lib/api.test.ts:

  • toRedirectHost β€” bare label, already-qualified, multi-level, apex/@/empty, idempotency, and the www.notex.com near-miss case.
  • addRedirect/updateRedirect/deleteRedirect β€” request shape, and the override:false vs omitted distinction.

Docs

README documents the new command and that sources may be given as bare or fully qualified.

πŸ“½οΈ Screencast

No visual changes.

βœ“ How to Validate

  1. npm install && npm run build
  2. gandi redirect list <domain> β€” confirm hosts print without a doubled domain suffix.
  3. gandi redirect update <domain> <source> --protocol https (no target) β€” confirm only protocol changes and the existing target/type/override are untouched.
  4. gandi redirect update <domain> <source> with no flags and no target β€” confirm it errors with "Nothing to update" instead of sending a PATCH.
  5. gandi redirect delete <domain> <source> β€” confirm the request succeeds (previously 400'd on a bare label).
  6. npm test β€” see the new toRedirectHost and redirect-request-shape coverage in src/lib/api.test.ts.

πŸ› οΈ Developer Checklist

  • Code is readable and maintainable
  • Tests included and passing (npm test β€” 41 passing)
  • PR is atomic and focused on a single feature or bug
  • Commits follow Conventional Commits

Validated locally: npm run lint clean, npm test (41 passing), npm run build (tsc) clean, and a live update against trakt.kud.io confirmed via a direct API read. No further manual/exploratory testing beyond that was performed.

Add redirect update capability that allows modifying redirects in place without
recreating them (preserving certificates). Introduce toRedirectHost() normalisation
to handle bare labels, apex notation, and idempotent FQDN qualification throughout
the redirect command surface. Update README with examples.
@kud
kud marked this pull request as ready for review August 1, 2026 19:18
@kud
kud merged commit 26e0bbe into main Aug 1, 2026
1 check passed
@kud
kud deleted the feat/redirect-update-normalise-fqdn branch August 1, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant