[PR #5536] [MERGED] fix(web): serve panel SPA routes from NoRoute #5914

Closed
opened 2026-11-02 04:04:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5536
Author: @w3struk
Created: 6/24/2026
Status: ✅ Merged
Merged: 6/24/2026
Merged by: @MHSanaei

Base: main ← Head: fix/spa-panel-routes


📝 Commits (5)

  • c0c8020 fix(web): serve panel SPA routes from NoRoute
  • 4a5d2ac fix(web): remove unreachable panel path guard
  • af6d8d8 Merge branch 'main' into fix/spa-panel-routes
  • 4d8a989 Merge branch 'main' into fix/spa-panel-routes
  • e54200a fix(web): allowlist static-asset extensions in SPA fallback

📊 Changes

4 files changed (+320 additions, -7 deletions)

View changed files

📝 internal/web/controller/dist.go (+6 -6)
📝 internal/web/controller/spa.go (+81 -0)
➕ internal/web/controller/spa_test.go (+228 -0)
📝 internal/web/web.go (+5 -1)

📄 Description

Summary

  • serve authenticated panel SPA deep links from NoRoute so client-side routes like /panel/hosts survive page refreshes
  • keep /panel/api, /panel/csrf-token, non-HTML accepts, non-GET requests, and static-file misses out of the SPA fallback
  • add controller tests for non-root base paths, auth behavior, API/static exclusions, and the explicit CSRF endpoint

Why

The frontend already registers the Hosts page, but the backend used a manual list of SPA GET routes. When the panel runs under a base path, refreshing /admin-*/panel/hosts missed that list and fell through to the global 404 handler.

Testing

  • docker run --rm -v "$PWD":/app -w /app/frontend node:22-alpine sh -c 'npm ci && npm run build'
  • docker run --rm -v "$PWD":/app -v /tmp/go-build-cache:/root/.cache/go-build -v /tmp/go-mod-cache:/go/pkg/mod -w /app golang:1.26-alpine sh -c 'apk add --no-cache build-base >/dev/null && CGO_ENABLED=1 go build ./... && CGO_ENABLED=1 go test ./...'
  • Built and pushed a test image: ghcr.io/w3struk/3x-ui:spa-hosts-routing-20260624
  • Manually verified /admin-w79p/panel/hosts works from that Docker image

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5536 **Author:** [@w3struk](https://github.com/w3struk) **Created:** 6/24/2026 **Status:** ✅ Merged **Merged:** 6/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/spa-panel-routes` --- ### 📝 Commits (5) - [`c0c8020`](https://github.com/MHSanaei/3x-ui/commit/c0c802021cdbe9235de6cf45e9e7a5180f07eaea) fix(web): serve panel SPA routes from NoRoute - [`4a5d2ac`](https://github.com/MHSanaei/3x-ui/commit/4a5d2ac292839fe19a42e8e5b4f7841002cea5b1) fix(web): remove unreachable panel path guard - [`af6d8d8`](https://github.com/MHSanaei/3x-ui/commit/af6d8d82bf5a848a5d0305300b982a525dcfe0ec) Merge branch 'main' into fix/spa-panel-routes - [`4d8a989`](https://github.com/MHSanaei/3x-ui/commit/4d8a98931f6d97323ce11d61ea9d58494b27d52a) Merge branch 'main' into fix/spa-panel-routes - [`e54200a`](https://github.com/MHSanaei/3x-ui/commit/e54200a02496b436b6f409b1fde4e3cba7019d19) fix(web): allowlist static-asset extensions in SPA fallback ### 📊 Changes **4 files changed** (+320 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/dist.go` (+6 -6) 📝 `internal/web/controller/spa.go` (+81 -0) ➕ `internal/web/controller/spa_test.go` (+228 -0) 📝 `internal/web/web.go` (+5 -1) </details> ### 📄 Description ## Summary - serve authenticated panel SPA deep links from `NoRoute` so client-side routes like `/panel/hosts` survive page refreshes - keep `/panel/api`, `/panel/csrf-token`, non-HTML accepts, non-GET requests, and static-file misses out of the SPA fallback - add controller tests for non-root base paths, auth behavior, API/static exclusions, and the explicit CSRF endpoint ## Why The frontend already registers the Hosts page, but the backend used a manual list of SPA GET routes. When the panel runs under a base path, refreshing `/admin-*/panel/hosts` missed that list and fell through to the global 404 handler. ## Testing - `docker run --rm -v "$PWD":/app -w /app/frontend node:22-alpine sh -c 'npm ci && npm run build'` - `docker run --rm -v "$PWD":/app -v /tmp/go-build-cache:/root/.cache/go-build -v /tmp/go-mod-cache:/go/pkg/mod -w /app golang:1.26-alpine sh -c 'apk add --no-cache build-base >/dev/null && CGO_ENABLED=1 go build ./... && CGO_ENABLED=1 go test ./...'` - Built and pushed a test image: `ghcr.io/w3struk/3x-ui:spa-hosts-routing-20260624` - Manually verified `/admin-w79p/panel/hosts` works from that Docker image --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:59 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5914
No description provided.