fix: resolve /api/auth/providers HTTP 404 by adding pass-through in Better Auth wildcard#1442
Merged
jaypatrick merged 3 commits intomainfrom Mar 28, 2026
Merged
Conversation
…x HTTP 404 Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/678c2b74-0332-4974-9626-fd8c09c850d1 Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix 404 error for GET /api/auth/providers
fix: register /api/auth/providers before Better Auth wildcard to resolve HTTP 404
Mar 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a routing-order issue in the Worker’s Hono app where /api/auth/providers was being shadowed by the Better Auth /api/auth/* wildcard, causing CI smoke tests to fail with 404s.
Changes:
- Registers
GET /api/auth/providersbefore the Better Auth/api/auth/*wildcard route. - Removes the now-unreachable duplicate
/api/auth/providersregistration from the pre-auth meta routes section. - Updates section header labels for clarity around route ordering.
…h in Better Auth wildcard Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/164915a1-c772-4e2d-b477-9d02a275e39b Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Copilot
AI
changed the title
fix: register /api/auth/providers before Better Auth wildcard to resolve HTTP 404
fix: resolve /api/auth/providers HTTP 404 by adding pass-through in Better Auth wildcard
Mar 28, 2026
Comment on lines
+361
to
+364
| app.on(['POST', 'GET'], '/api/auth/*', async (c, next) => { | ||
| // Pass through for custom endpoint — let it reach its registered handler with | ||
| // full CORS and rate-limiting middleware applied. | ||
| if (c.req.path === '/api/auth/providers') return next(); |
There was a problem hiding this comment.
No regression test covers the new pass-through behavior for /api/auth/providers. Since this endpoint was previously broken by the /api/auth/* wildcard routing order, please add a unit test (e.g., in worker/hono-app.test.ts) that asserts GET /api/auth/providers is not 404 and that it receives expected middleware effects (at least CORS header for an allowed Origin, and/or anonymous-tier rate limiting).
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hono routes in registration order.
app.get('/api/auth/providers', ...)was originally registered at ~line 635 — after theapp.on(['POST', 'GET'], '/api/auth/*', ...)wildcard at ~line 356. The wildcard intercepted every/api/auth/*request first; Better Auth returned 404 (dur=0.0) because it has no knowledge of this custom endpoint. Both CI smoke tests were failing as a result.A first attempt moved the handler before the wildcard, but that placed it before the CORS and unified auth/rate-limiting middleware, causing the endpoint to lose CORS headers and anonymous-tier rate limiting.
The correct fix keeps
app.get('/api/auth/providers', ...)in the pre-auth meta section (after CORS + rate-limiting middleware) and adds an explicitreturn next()pass-through in the Better Auth wildcard for this path, so the wildcard never intercepts it.Changes
return next()pass-through in the Better Auth wildcard handler forc.req.path === '/api/auth/providers', so the request falls through to the specific handler rather than returning 404nextparameter to the Better Auth wildcard handler signature to enable the pass-throughapp.get('/api/auth/providers', ...)in the pre-auth meta section (after CORS + rate-limiting middleware), preserving CORS header delivery and anonymous-tier rate limitingTesting
GET /api/auth/providersandSSR API proxy /api/auth/providersexpected to go greenZero Trust Architecture Checklist
Worker / Backend
handleAuthProvidersis a public read-only endpoint already inPRE_AUTH_PATHS)*) on write/authenticated endpoints — N/A (no new endpoints; CORS coverage preserved by keeping handler after CORS middleware)[vars]) — N/A (no secret access changed).prepare().bind()(no string interpolation) — N/A (no DB queries)Frontend / Angular
CanActivateFnauth guards — N/AlocalStorage) — N/AFrontend not touched. ZTA checklist completed above for
worker/change.Original prompt
Problem
GET /api/auth/providersreturns HTTP 404 withdur=0.0inserver-timing. This is proven by:The zero duration means Hono matched the route and returned before any handler ran.
Root Cause
In
worker/hono-app.ts, theapp.get('/api/auth/providers', ...)handler is registered at line ~635 (after theroutessub-app declaration), but the Better Auth wildcard handler is registered at line ~356:Because
/api/auth/providersmatches the/api/auth/*glob, Hono routes it to the Better Auth handler first. SinceBETTER_AUTH_SECRETis set but Better Auth doesn't know about/api/auth/providers, it callsc.notFound()— returning a 404 with zero content before the actual handler ever runs.Fix Required
In
worker/hono-app.ts, move theapp.get('/api/auth/providers', ...)registration to before theapp.on(['POST', 'GET'], '/api/auth/*', ...)handler, so it takes priority.Specifically:
app.on(['POST', 'GET'], '/api/auth/*', ...)block (currently around line 356)./api/auth/providersroute handler immediately before it:app.get('/api/auth/providers', ...)registration that currently exists around line 635 (in the "Pre-auth API meta routes" section), along with its comment:Expected Result
GET /api/auth/providers→ HTTP 200 with JSON body{"emailPassword":true,"github":false,"google":false,"mfa":true}❌ /api/auth/providers returned HTTP 404→✅ /api/auth/providers returned HTTP 200❌ SSR API proxy /api/auth/providers returned HTTP 404→✅ SSR API proxy /api/auth/providers returned HTTP 200Files to Change
worker/hono-app.ts— move theapp.get('/api/auth/providers', ...)call from ~line 635 to immediately before theapp.on(['POST', 'GET'], '/api/auth/*', ...)block at ~line 356. No other files need changing.Notes
handleAuthProvidersis already imported at the top of the file (import { handleAuthProviders } from './handlers/auth-providers.ts') — no new imports needed.The following is the prior conversation context from the user's chat exploration (may be truncated):
Assistant: ## Why Brotli isn't supported
The root cause is a Cloudflare Workers runtime limitation. The
CompressionStreamWeb API — which is what Hono'scompress()middleware uses internally — only supports"gzip"and"deflate"in the Workers V8 isolate environment. This is a deliberate platform constraint, not a Hono limitation. From the Cloudflare community:The only workaround would be to ship a Brotli WASM binary with the Worker, which adds bundle size and CPU overhead — almost certainly not worth it.
Performance impact of being gzip-only
Here's the honest breakdown for your specific use case:
The important nuance for your deployment
Cloudflare's CDN edge layer (the Cloudflare proxy in front of your Worker) does support Brotli for static assets served via Workers Sta...
This pull request was created from Copilot chat.
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.