fix: use NEXT_PUBLIC_APP_URL for affiliate fallback redirects - #113
Conversation
Greptile SummaryFixes fallback redirects in the affiliate click endpoint that were sending users to
Confidence Score: 4/5Safe to merge — all three fallback redirects now point to the correct public URL, resolving the user-facing broken redirect behind Railway's proxy. The redirect fix is correct and consistent with the existing pattern in the same file. The one residual gap is that landedUrl in recordClick still captures the internal localhost:8080 URL, so affiliate analytics will store inaccurate click origins, but this does not affect end-user functionality. The recordClick call on line 54 of src/app/api/affiliates/click/route.ts deserves a follow-up to swap request.url for the public URL, mirroring this PR's approach. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Railway Proxy
participant Next.js Handler
participant Supabase
User->>Railway Proxy: GET /api/affiliates/click?ugig_ref=CODE
Railway Proxy->>Next.js Handler: forwards request (request.url = localhost:8080/...)
alt Missing ugig_ref param
Next.js Handler-->>User: redirect(NEXT_PUBLIC_APP_URL + /affiliates) fixed
else
Next.js Handler->>Supabase: lookup tracking_code
alt Unknown / unapproved ref
Next.js Handler-->>User: redirect(NEXT_PUBLIC_APP_URL + /affiliates) fixed
else Valid ref
Next.js Handler->>Supabase: recordClick(landedUrl=request.url still localhost)
Next.js Handler-->>User: redirect to offer URL + set cookies
end
end
alt Unhandled exception
Next.js Handler-->>User: redirect(NEXT_PUBLIC_APP_URL + /affiliates) fixed
end
|
What
Replaces request.url with NEXT_PUBLIC_APP_URL for fallback redirects in the affiliate click endpoint.
Why
Closes #94. Behind Railway's reverse proxy, request.url contains the internal server URL (http://localhost:8080) instead of the public-facing URL. This causes fallback redirects to send users to an unreachable localhost URL.
How
Changed three fallback redirects in src/app/api/affiliates/click/route.ts:
All now use process.env.NEXT_PUBLIC_APP_URL || "https://ugig.net" as the base URL, matching the pattern already used elsewhere in the same file.
Testing