From 2616f2563823908364997403ce58c5a4ba04f0e5 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sat, 9 May 2026 01:52:57 +0200 Subject: [PATCH] refactor(frontend): organize entry HTML + bootstrap JS into folders - Move entry HTML files: frontend/*.html -> frontend/html/*.html - Move per-page bootstrap modules: src/{index,login,settings,inbounds,xray,subpage}.js -> src/entries/ - Update vite.config rollup inputs and dev-mode MIGRATED_ROUTES to /html/.html - Build output now lands at web/dist/html/.html - serveDistPage and subController updated to read from dist/html/ Cleans up the flat frontend/ root which previously interleaved 6 HTML files with package.json, README, src/, etc. The src/ root similarly gets rid of 6 entry .js files mixed in alongside api/, components/, models/, etc. Co-Authored-By: Claude Opus 4.7 --- frontend/{ => html}/inbounds.html | 2 +- frontend/{ => html}/index.html | 2 +- frontend/{ => html}/login.html | 2 +- frontend/{ => html}/settings.html | 2 +- frontend/{ => html}/subpage.html | 2 +- frontend/{ => html}/xray.html | 2 +- frontend/src/{ => entries}/inbounds.js | 0 frontend/src/{ => entries}/index.js | 0 frontend/src/{ => entries}/login.js | 0 frontend/src/{ => entries}/settings.js | 0 frontend/src/{ => entries}/subpage.js | 0 frontend/src/{ => entries}/xray.js | 0 frontend/vite.config.js | 45 +++++++++++++------------- sub/subController.go | 4 +-- sub/subService.go | 2 +- web/controller/dist.go | 6 ++-- 16 files changed, 34 insertions(+), 35 deletions(-) rename frontend/{ => html}/inbounds.html (80%) rename frontend/{ => html}/index.html (80%) rename frontend/{ => html}/login.html (83%) rename frontend/{ => html}/settings.html (80%) rename frontend/{ => html}/subpage.html (83%) rename frontend/{ => html}/xray.html (81%) rename frontend/src/{ => entries}/inbounds.js (100%) rename frontend/src/{ => entries}/index.js (100%) rename frontend/src/{ => entries}/login.js (100%) rename frontend/src/{ => entries}/settings.js (100%) rename frontend/src/{ => entries}/subpage.js (100%) rename frontend/src/{ => entries}/xray.js (100%) diff --git a/frontend/inbounds.html b/frontend/html/inbounds.html similarity index 80% rename from frontend/inbounds.html rename to frontend/html/inbounds.html index 584e5d1d..57485c92 100644 --- a/frontend/inbounds.html +++ b/frontend/html/inbounds.html @@ -8,6 +8,6 @@
- + diff --git a/frontend/index.html b/frontend/html/index.html similarity index 80% rename from frontend/index.html rename to frontend/html/index.html index 2d5853bb..b2d45443 100644 --- a/frontend/index.html +++ b/frontend/html/index.html @@ -8,6 +8,6 @@
- + diff --git a/frontend/login.html b/frontend/html/login.html similarity index 83% rename from frontend/login.html rename to frontend/html/login.html index f92d1935..ba8e1e05 100644 --- a/frontend/login.html +++ b/frontend/html/login.html @@ -9,6 +9,6 @@
- + diff --git a/frontend/settings.html b/frontend/html/settings.html similarity index 80% rename from frontend/settings.html rename to frontend/html/settings.html index 455deb22..da144ba7 100644 --- a/frontend/settings.html +++ b/frontend/html/settings.html @@ -8,6 +8,6 @@
- + diff --git a/frontend/subpage.html b/frontend/html/subpage.html similarity index 83% rename from frontend/subpage.html rename to frontend/html/subpage.html index d0af6c7e..11632ae8 100644 --- a/frontend/subpage.html +++ b/frontend/html/subpage.html @@ -9,6 +9,6 @@
- + diff --git a/frontend/xray.html b/frontend/html/xray.html similarity index 81% rename from frontend/xray.html rename to frontend/html/xray.html index 80915eb7..3c16d29f 100644 --- a/frontend/xray.html +++ b/frontend/html/xray.html @@ -8,6 +8,6 @@
- + diff --git a/frontend/src/inbounds.js b/frontend/src/entries/inbounds.js similarity index 100% rename from frontend/src/inbounds.js rename to frontend/src/entries/inbounds.js diff --git a/frontend/src/index.js b/frontend/src/entries/index.js similarity index 100% rename from frontend/src/index.js rename to frontend/src/entries/index.js diff --git a/frontend/src/login.js b/frontend/src/entries/login.js similarity index 100% rename from frontend/src/login.js rename to frontend/src/entries/login.js diff --git a/frontend/src/settings.js b/frontend/src/entries/settings.js similarity index 100% rename from frontend/src/settings.js rename to frontend/src/entries/settings.js diff --git a/frontend/src/subpage.js b/frontend/src/entries/subpage.js similarity index 100% rename from frontend/src/subpage.js rename to frontend/src/entries/subpage.js diff --git a/frontend/src/xray.js b/frontend/src/entries/xray.js similarity index 100% rename from frontend/src/xray.js rename to frontend/src/entries/xray.js diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 8f49efa9..f1cde1a0 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -6,21 +6,20 @@ import path from 'node:path'; // via embed.FS without reaching outside the web/ tree. const outDir = path.resolve(__dirname, '../web/dist'); -// In production the Go binary serves /panel/ from web/dist/.html. -// In dev the Vue app lives at /index.html, /settings.html, ... while AppSidebar -// links use the production-style /panel/ URLs. Map each migrated route -// to its Vite entry so the sidebar works without relying on the Go backend -// for already-ported pages. Unmigrated routes (inbounds, xray) fall through -// to the proxy. +// In production the Go binary serves /panel/ from web/dist/html/.html. +// In dev the Vue app lives at /html/index.html, /html/settings.html, ... while +// AppSidebar links use the production-style /panel/ URLs. Map each +// migrated route to its Vite entry so the sidebar works without relying on +// the Go backend for already-ported pages. const MIGRATED_ROUTES = { - '/panel': '/index.html', - '/panel/': '/index.html', - '/panel/settings': '/settings.html', - '/panel/settings/': '/settings.html', - '/panel/inbounds': '/inbounds.html', - '/panel/inbounds/': '/inbounds.html', - '/panel/xray': '/xray.html', - '/panel/xray/': '/xray.html', + '/panel': '/html/index.html', + '/panel/': '/html/index.html', + '/panel/settings': '/html/settings.html', + '/panel/settings/': '/html/settings.html', + '/panel/inbounds': '/html/inbounds.html', + '/panel/inbounds/': '/html/inbounds.html', + '/panel/xray': '/html/xray.html', + '/panel/xray/': '/html/xray.html', }; // Build a proxy config that suppresses ECONNREFUSED noise when the Go @@ -103,12 +102,12 @@ export default defineConfig({ // As pages get ported in later phases, add their entrypoints here. rollupOptions: { input: { - index: path.resolve(__dirname, 'index.html'), - login: path.resolve(__dirname, 'login.html'), - settings: path.resolve(__dirname, 'settings.html'), - inbounds: path.resolve(__dirname, 'inbounds.html'), - xray: path.resolve(__dirname, 'xray.html'), - subpage: path.resolve(__dirname, 'subpage.html'), + index: path.resolve(__dirname, 'html/index.html'), + login: path.resolve(__dirname, 'html/login.html'), + settings: path.resolve(__dirname, 'html/settings.html'), + inbounds: path.resolve(__dirname, 'html/inbounds.html'), + xray: path.resolve(__dirname, 'html/xray.html'), + subpage: path.resolve(__dirname, 'html/subpage.html'), }, output: { // Split vendor deps into stable chunks so each page only pulls @@ -144,9 +143,9 @@ export default defineConfig({ port: 5173, strictPort: true, proxy: makeBackendProxy('http://localhost:2053', [ - // Patterns are anchored regex so /login.html and /index.html - // (which Vite serves itself) are NOT forwarded — only the bare - // backend paths and their sub-routes. + // Patterns are anchored regex so /html/login.html, /html/index.html + // etc. (which Vite serves itself) are NOT forwarded — only the + // bare backend paths and their sub-routes. '^/(login|logout|getTwoFactorEnable|csrf-token)$', '^/(panel|server)(/|$)', ]), diff --git a/sub/subController.go b/sub/subController.go index ddb24c11..76aa1504 100644 --- a/sub/subController.go +++ b/sub/subController.go @@ -148,14 +148,14 @@ func (a *SUBController) subs(c *gin.Context) { } } -// serveSubPage renders web/dist/subpage.html for the current subscription +// serveSubPage renders web/dist/html/subpage.html for the current subscription // request. The Vite-built SPA reads window.__SUB_PAGE_DATA__ on mount — // we inject that here, along with window.__X_UI_BASE_PATH__ so the // page's static asset references resolve correctly when the panel runs // behind a URL prefix. func (a *SUBController) serveSubPage(c *gin.Context, basePath string, page PageData) { dist := webpkg.EmbeddedDist() - body, err := dist.ReadFile("dist/subpage.html") + body, err := dist.ReadFile("dist/html/subpage.html") if err != nil { c.String(http.StatusInternalServerError, "missing embedded subpage") return diff --git a/sub/subService.go b/sub/subService.go index 33605ad6..d326e0f1 100644 --- a/sub/subService.go +++ b/sub/subService.go @@ -1350,7 +1350,7 @@ func searchHost(headers any) string { return "" } -// PageData is a view model for subpage.html +// PageData is a view model for html/subpage.html // PageData contains data for rendering the subscription information page. type PageData struct { Host string diff --git a/web/controller/dist.go b/web/controller/dist.go index 24eca57d..9a00a8bd 100644 --- a/web/controller/dist.go +++ b/web/controller/dist.go @@ -36,8 +36,8 @@ func SetDistFS(fs embed.FS) { // GETs can hit the 304 path on repeat loads. var distPageBuildTime = time.Now() -// serveDistPage reads `dist/` from the embedded FS and writes it -// to the response. Two transforms run before send: +// serveDistPage reads `dist/html/` from the embedded FS and writes +// it to the response. Two transforms run before send: // // 1. `` is injected // just before so the AppSidebar's link generator sees the @@ -51,7 +51,7 @@ var distPageBuildTime = time.Now() // reaches users on the next reload; the long-hashed JS/CSS files // under /assets/ stay cacheable indefinitely. func serveDistPage(c *gin.Context, name string) { - body, err := distFS.ReadFile("dist/" + name) + body, err := distFS.ReadFile("dist/html/" + name) if err != nil { c.String(http.StatusInternalServerError, "missing embedded page: %s", name) return