Skip to content

fix: remove server-side path redirect to prevent CDN-cached redirect loops#7

Merged
Starry-Sky-World merged 1 commit into
mainfrom
feat/langfuse-trace-notice
May 22, 2026
Merged

fix: remove server-side path redirect to prevent CDN-cached redirect loops#7
Starry-Sky-World merged 1 commit into
mainfrom
feat/langfuse-trace-notice

Conversation

@Starry-Sky-World
Copy link
Copy Markdown

@Starry-Sky-World Starry-Sky-World commented May 22, 2026

Problem

Server-side \MapFrontendPath\ redirect was causing infinite redirect loops when CDN (Cloudflare) cached 302 responses for different themes:

\
/console → 302 → /dashboard → 302 → /console → ... → ERR_TOO_MANY_REDIRECTS
\\

Root Cause

  1. User A (theme=default) visits /console\ → server 302 → /dashboard\ → Cloudflare caches this 302
  2. User B (theme=classic) visits /dashboard\ → server 302 → /console\ → Cloudflare caches this 302
  3. Any user hits /console\ → cached 302 → /dashboard\ → cached 302 → /console\ → infinite loop

The redirect response had no \Cache-Control\ header (it returned before the
o-cache\ header was set), so CDN cached it with the default TTL.

Fix

Remove the server-side path redirect entirely. SPA apps don't need server-side redirects — the server should always serve the correct theme's \index.html\ for any route, and let the frontend router handle navigation.

This eliminates:

  • 302 responses that can be cached by CDN
  • Theme-dependent redirect direction conflicts
  • The need for \MapFrontendPath\ in the web router

Summary by CodeRabbit

  • Bug Fixes
    • Removed unnecessary path redirects in frontend asset serving, allowing assets to be delivered directly while maintaining proper fallback behavior to the theme's index page.

Review Change Stack

…loops

The server-side MapFrontendPath redirect was causing infinite redirect
loops when CDN (Cloudflare) cached 302 responses for different themes:
- User A (theme=default) visits /console → 302 → /dashboard (cached)
- User B (theme=classic) visits /dashboard → 302 → /console (cached)
- Any user hits /console → cached 302 → /dashboard → cached 302 → /console → loop

Fix: Remove the server-side redirect entirely. Instead, always serve the
correct theme's index.html for any SPA route. The frontend router will
handle navigation to the correct page within its own theme.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7b1631e6-6ac8-461f-8aa0-ad62f6aa968c

📥 Commits

Reviewing files that changed from the base of the PR and between 3e101f8 and cd17bcf.

📒 Files selected for processing (1)
  • router/web-router.go
💤 Files with no reviewable changes (1)
  • router/web-router.go

📝 Walkthrough

Walkthrough

The NoRoute handler in the web router's SetWebRouter function is simplified by removing the path-mapping redirect logic. Requests now proceed directly to theme filesystem selection and asset serving instead of being conditionally redirected based on mapped frontend paths.

Changes

Web Router Handler

Layer / File(s) Summary
Remove path-mapping redirect from NoRoute handler
router/web-router.go
The conditional redirect using common.MapFrontendPath is removed, eliminating the intermediate redirect and letting requests proceed directly to theme filesystem selection and fallback index serving.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A rabbit hops through shorter code,
No detours on the routing road,
Direct paths now serve the day,
Simpler flow shows clearer way! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing a server-side path redirect to prevent CDN-cached redirect loops, which directly corresponds to the changeset that removes MapFrontendPath redirect logic from the NoRoute handler.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/langfuse-trace-notice

Comment @coderabbitai help to get the list of available commands and usage tips.

@Starry-Sky-World Starry-Sky-World merged commit b10a188 into main May 22, 2026
4 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the server-side path redirection logic in router/web-router.go. While this change is intended to fix CDN caching loops, it may break automatic path normalization for deep links and bookmarks across different themes. The reviewer suggests restoring the redirection logic but adding a Cache-Control: no-cache header to the response to prevent the CDN from caching the redirect, thereby maintaining functionality while resolving the caching issue.

I am having trouble creating individual review comments. Click here to see my feedback.

router/web-router.go (41-47)

high

Removing the server-side path redirect entirely fixes the CDN caching loop, but it also breaks the automatic path normalization between themes for deep links and bookmarks. For example, a user with the default theme visiting a /console URL (a classic path) will now stay on /console but be served the default theme's SPA. If the default theme's frontend router is not specifically configured to handle or redirect /console, the user will see a 404.

If the goal is to maintain the current URL behavior while fixing the CDN issue, a better approach would be to keep the redirect but explicitly set the Cache-Control: no-cache header on the 302 response. This prevents the CDN from caching the theme-dependent redirect.

If you prefer to proceed with the removal, please ensure that both the default and classic frontend applications are updated to handle cross-theme path mapping internally.

		if redirectPath := common.MapFrontendPath(theme, c.Request.URL.Path); redirectPath != "" && redirectPath != c.Request.URL.Path {
			if c.Request.URL.RawQuery != "" {
				redirectPath = redirectPath + "?" + c.Request.URL.RawQuery
			}
			c.Header("Cache-Control", "no-cache")
			c.Redirect(http.StatusFound, redirectPath)
			return
		}

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