mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-05-13 17:46:02 +00:00
fix(frontend): route /panel/<route> to migrated pages in dev
The sidebar links to production-style URLs like /panel/settings, but in dev that gets proxied to the legacy Go template — which fails because we haven't loaded the legacy asset chain. Add a proxy bypass so /panel and /panel/settings are served from index.html / settings.html on the Vite dev server itself. Unmigrated routes (inbounds, xray) still proxy to Go. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
100a3e5167
commit
f773f85cf9
1 changed files with 23 additions and 0 deletions
|
|
@ -6,6 +6,19 @@ 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/<route> from web/dist/<route>.html.
|
||||
// In dev the Vue app lives at /index.html, /settings.html, ... while AppSidebar
|
||||
// links use the production-style /panel/<route> 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.
|
||||
const MIGRATED_ROUTES = {
|
||||
'/panel': '/index.html',
|
||||
'/panel/': '/index.html',
|
||||
'/panel/settings': '/settings.html',
|
||||
'/panel/settings/': '/settings.html',
|
||||
};
|
||||
|
||||
// Build a proxy config that suppresses ECONNREFUSED noise when the Go
|
||||
// backend isn't running locally. Real errors (timeouts, 5xx, etc.) still
|
||||
// surface in the Vite log.
|
||||
|
|
@ -15,6 +28,16 @@ function makeBackendProxy(target, patterns) {
|
|||
config[pattern] = {
|
||||
target,
|
||||
changeOrigin: true,
|
||||
// Returning a path from bypass tells Vite to serve that file from
|
||||
// its own dev server instead of forwarding the request — used here
|
||||
// to short-circuit /panel/<route> for pages we've already migrated.
|
||||
bypass(req) {
|
||||
const url = req.url.split('?')[0];
|
||||
if (Object.prototype.hasOwnProperty.call(MIGRATED_ROUTES, url)) {
|
||||
return MIGRATED_ROUTES[url];
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
configure(proxy) {
|
||||
proxy.on('error', (err) => {
|
||||
if (err.code === 'ECONNREFUSED') return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue