-
Notifications
You must be signed in to change notification settings - Fork 47
Add the Bump proxy for previewing API docs in PRs #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for redpanda-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis pull request introduces Netlify infrastructure for API documentation proxying. It adds a Netlify configuration file that specifies Node 24 runtime, sets the documentation directory as the publishing path, and defines an edge function mapping. A new edge function is added that proxies API documentation requests through bump.sh, applies path-based theming, injects custom widgets (head script, header, footer), handles request redirects, includes resilient fetching with exponential backoff, and provides graceful error handling with fallback responses. Sequence DiagramsequenceDiagram
participant Client
participant EdgeFunc as Edge Function<br/>(proxy-api-docs)
participant BumpSh as bump.sh
participant WidgetSrc as Widget Sources
Client->>EdgeFunc: Request /api/v1/docs
EdgeFunc->>EdgeFunc: Normalize path & check<br/>for legacy redirects
alt Legacy Route Detected
EdgeFunc-->>Client: 301 Redirect to<br/>new path
else Current Route
EdgeFunc->>EdgeFunc: Map path to<br/>header color
EdgeFunc->>BumpSh: Fetch documentation<br/>with retry logic
alt Non-HTML Response
BumpSh-->>EdgeFunc: Return raw content
EdgeFunc-->>Client: Raw response
else HTML Response
BumpSh-->>EdgeFunc: HTML content
EdgeFunc->>WidgetSrc: Fetch head widget<br/>with retry
EdgeFunc->>WidgetSrc: Fetch header widget<br/>with retry
EdgeFunc->>WidgetSrc: Fetch footer widget<br/>with retry
EdgeFunc->>EdgeFunc: Parse HTML &<br/>inject widgets
EdgeFunc-->>Client: Modified HTML<br/>with caching headers
end
end
alt Fetch/Processing Error
EdgeFunc-->>Client: 503 Error Page<br/>(graceful fallback)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@netlify/edge-functions/proxy-api-docs.js`:
- Around line 7-24: The redirect logic currently drops query parameters; update
the redirect branch that checks redirects[normalizedPath] to append the original
request's url.search (e.g., url.search) to the target path when calling
Response.redirect so query string and anchors are preserved; modify the redirect
call that uses Response.redirect(`${url.origin}${redirects[normalizedPath]}`,
301) to include url.search (and ensure you don't duplicate "?" if search is
empty) while keeping the existing normalizedPath and redirects lookup.
🧹 Nitpick comments (1)
netlify/edge-functions/proxy-api-docs.js (1)
151-172: Retry on 429/5xx responses to improve resilience.
fetchWithRetrycurrently retries only on network errors and timeouts. Transient 429 (rate limit) and 5xx responses from Bump.sh will fail immediately. Consider treating them as retryable and respecting theRetry-Afterheader to improve robustness.♻️ Suggested update
async function fetchWithRetry(url, options, maxRetries = 3) { for (let attempt = 1; attempt <= maxRetries; attempt++) { try { const response = await fetch(url, { ...options, signal: AbortSignal.timeout(10000), // 10 second timeout }); - return response; + if (response.ok) return response; + + const retryable = response.status === 429 || response.status >= 500; + if (!retryable || attempt === maxRetries) return response; + + response.body?.cancel(); + const retryAfter = response.headers.get("retry-after"); + const delay = + retryAfter && Number.isFinite(Number(retryAfter)) + ? Number(retryAfter) * 1000 + : Math.pow(2, attempt) * 1000; + await new Promise(resolve => setTimeout(resolve, delay)); + continue; } catch (error) { console.warn(`Attempt ${attempt} failed for ${url}:`, error.message); if (attempt === maxRetries) { throw error; } const delay = Math.pow(2, attempt) * 1000; await new Promise(resolve => setTimeout(resolve, delay)); } } }
Description
Allows us to preview API docs in preview builds by adding the proxy for Bump.sh.
Page previews
Checks