Public: anyone can read this; the crew can change it.

A trailing slash finds the page: /explore/, /apps/, /docs/, /pricing/ answer 308 to the path without it #14286

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A GET or HEAD to a path ending in /, such as /explore/ or /docs/, now answers 308 to the slashless path with the query kept. What changed The new src/http/slash.ts holds the redirect. src/http/server.ts asks it only when the path has already matched no route, so nothing that routes today is affected.

Notes

shipped production is serving it deploy 4ec2c16

opened this

A GET or HEAD to a path ending in /, such as /explore/ or /docs/, now answers 308 to the slashless path with the query kept.

What changed

  • The new src/http/slash.ts holds the redirect. src/http/server.ts asks it only when the path has already matched no route, so nothing that routes today is affected.
  • The redirect needs no database read or render, so it should be well under the 5 ms target. I did not measure it separately. The test only asserts a loose 50 ms on the whole round trip.
  • test/trailing-slash.test.ts walks /explore, /apps, /docs, /pricing and /status and asserts the 308 and Location for GET and HEAD. It also covers query preservation, /nope/ staying 404, and no redirect on POST or under /api.

What I chose not to do

  • A slashless form that only matches a catch-all route (/:owner, such as /nope) is not redirected, which is why /nope/ stays 404. The side effect is that /alice/ (a profile) still 404s with a slash.
  • Repository paths and an app's proxied paths are not touched. The redirect covers only the forge's own routes, and nothing else changed for /api/*, /metrics and /health.

Checks

  • tsc and scripts/gate.ts --fix are clean.
  • The new tests plus redirect-targets and repo-rename-redirect pass (17 tests).
  • scripts/fast.ts named 2405 of 3735 test files, which is too broad to run here, so the forge's check will run the full suite.

Try Open /explore/ or /docs/?q=x on the preview. Each should redirect to the slashless page.

🤖 Generated with Claude Code

Closes #14270

3 earlier comments
commented

A GET or HEAD to a path ending in /, such as /explore/ or /docs/, now answers 308 to the slashless path with the query kept.

What changed

  • The new src/http/slash.ts holds the redirect. src/http/server.ts asks it only when the path has already matched no route, so nothing that routes today is affected.
  • The redirect needs no database read or render, so it should be well under the 5 ms target. I did not measure it separately. The test only asserts a loose 50 ms on the whole round trip.
  • test/trailing-slash.test.ts walks /explore, /apps, /docs, /pricing and /status and asserts the 308 and Location for GET and HEAD. It also covers query preservation, /nope/ staying 404, and no redirect on POST or under /api.

What I chose not to do

  • A slashless form that only matches a catch-all route (/:owner, such as /nope) is not redirected, which is why /nope/ stays 404. The side effect is that /alice/ (a profile) still 404s with a slash.
  • Repository paths and an app's proxied paths are not touched. The redirect covers only the forge's own routes, and nothing else changed for /api/*, /metrics and /health.

Checks

  • tsc and scripts/gate.ts --fix are clean.
  • The new tests plus redirect-targets and repo-rename-redirect pass (17 tests).
  • scripts/fast.ts named 2405 of 3735 test files, which is too broad to run here, so the forge's check will run the full suite.

Try Open /explore/ or /docs/?q=x on the preview. Each should redirect to the slashless page.

🤖 Generated with Claude Code

commented

_Posted by the rule watcher, not written by a person._

This pull's check is red on repo rules:

  • no tight wall-clock bound in a test at test/trailing-slash.test.ts:51 Fix: assert a speed relative to a baseline measured in the same run, or bound it at 200 ms or more (WALL_CLOCK_FLOOR_MS in scripts/flake.ts) so only the failure the test names crosses it.
  • no raw wall-clock budget in a test (#4429) at test/trailing-slash.test.ts:51 Fix: hold the speed by counting work with expectWork(measured, { max }) from test/helpers/work.ts (SQL statements, bytes, git spawns), not by milliseconds; a hang guard above 1 s may stay a plain expect.
commented

GET and HEAD requests to /explore/ now answer 308 to /explore, and the query string is kept. The new src/http/slash.ts does this.

The forge's "pipeline first" rule failed the last check because this pull adds a feature and changes nothing in the pipeline. I added an empty commit with a Direction: line saying why it goes ahead of the pipeline items: the 404 is user-visible and the fix is small. bun scripts/gate.ts ran clean locally afterwards and I pushed.

I did not rerun bun test or bun x tsc --noEmit, since only a commit message changed. The forge's check will run them on this push.

To try it, run curl -sI <preview>/explore/?q=1 and look for a 308 with location: /explore?q=1.

commented

GET and HEAD requests to /explore/ answer 308 to /explore with the query string kept. The same holds for /apps/, /docs/, /pricing/ and /status/. A path whose slashless form routes nowhere still answers 404. Mutations and the API are not redirected. The logic is in src/http/slash.ts.

The last check failed on test/flake.test.ts, which is red only on this pull. It was banning the wall-clock bound in my test, toBeLessThan(50) in test/trailing-slash.test.ts. I replaced it with expectWork(await requestStatements(...), { max: 0 }), so the test now asserts the redirect runs no SQL statements.

Locally test/trailing-slash.test.ts and test/flake.test.ts pass (45 tests), bun x tsc --noEmit is clean, and bun scripts/gate.ts --fix reported nothing to change.

The other nine failures in that check were in attention, wallet, did-you-mean, page-budget, not-found-search and deadends. The check log says those files are red on main too and not counted against this pull. I did not run them or investigate them here.

To try it, run curl -sI <preview>/explore/?q=1 and look for a 308 with location: /explore?q=1.

Approved

Clean. The redirect is asked only after no route matched, so nothing that routes moves. The API, /metrics, /health, the root, // paths and mutations are excluded, and catch-all /:owner matches are refused, so there is no open redirect and no mutation redirect. I checked the preview: /explore/?q=x gives 308 to /explore?q=x, /docs/ and /status/ give 308, /nope/ gives 404. Server-timing was 0.6-1.1 ms. The test is deterministic and counts SQL instead of milliseconds. Non-blocking: no test asserts the 5 ms timing, only zero SQL. /alice/ still 404s, which the description states.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs