-
+
{form.formState.errors.domain && (
{form.formState.errors.domain.message}
)}
diff --git a/frontend/app/(main)/websites/[zoneId]/page-client.tsx b/frontend/app/(main)/websites/[zoneId]/page-client.tsx
index 20d92caa..21a48565 100644
--- a/frontend/app/(main)/websites/[zoneId]/page-client.tsx
+++ b/frontend/app/(main)/websites/[zoneId]/page-client.tsx
@@ -1,6 +1,6 @@
'use client';
-import {useParams, usePathname, useRouter, useSearchParams} from 'next/navigation';
+import {usePathname, useRouter, useSearchParams} from 'next/navigation';
import {useCallback, useEffect, useMemo, useState} from 'react';
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query';
import {ArrowLeft, Globe, Pencil, Trash2} from 'lucide-react';
@@ -40,10 +40,12 @@ function getZonePageTab(value: string | null | undefined): ZonePageTab {
return zoneTabs.includes(value as ZonePageTab) ? (value as ZonePageTab) : 'overview';
}
-export function ZonePageClient() {
- const params = useParams();
- const zoneId = Number(params?.zoneId);
+function getZoneIdFromPathname(pathname: string | null): number {
+ const match = pathname?.match(/^\/websites\/([^/]+)$/);
+ return Number(match?.[1]);
+}
+export function ZonePageClient() {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
@@ -51,6 +53,7 @@ export function ZonePageClient() {
const router = useRouter();
const pathname = usePathname();
+ const zoneId = useMemo(() => getZoneIdFromPathname(pathname), [pathname]);
const searchParams = useSearchParams();
const queryClient = useQueryClient();
const activeTab = useMemo(
diff --git a/frontend/tests/zone/websites-page.test.tsx b/frontend/tests/zone/websites-page.test.tsx
index 84820773..d995d039 100644
--- a/frontend/tests/zone/websites-page.test.tsx
+++ b/frontend/tests/zone/websites-page.test.tsx
@@ -34,14 +34,14 @@ describe('WebsitesPage', () => {
vi.mocked(ZoneService.list).mockResolvedValue([
{
id: 42,
- domain: 'arctel.de',
+ domain: 'example.com',
domain_count: 3,
created_at: '',
updated_at: '',
},
{
id: 43,
- domain: 'example.com',
+ domain: 'another.com',
domain_count: 0,
created_at: '',
updated_at: '',
@@ -50,18 +50,18 @@ describe('WebsitesPage', () => {
renderPage();
- expect(await screen.findByText('arctel.de')).toBeVisible();
+ expect(await screen.findByText('example.com')).toBeVisible();
expect(screen.getByText('3')).toBeVisible();
expect(screen.getByText('0')).toBeVisible();
expect(screen.getByRole('columnheader', {name: '根域'})).toBeVisible();
fireEvent.change(screen.getByPlaceholderText('搜索 Zone 根域'), {
- target: {value: 'arctel'},
+ target: {value: 'example'},
});
expect(screen.getByRole('link', {name: '管理'})).toHaveAttribute(
'href',
'/websites/42',
);
- expect(screen.queryByText('example.com')).not.toBeInTheDocument();
+ expect(screen.queryByText('another.com')).not.toBeInTheDocument();
});
});
diff --git a/frontend/tests/zone/zone-domain-selector.test.tsx b/frontend/tests/zone/zone-domain-selector.test.tsx
index db7ff332..d5e42b07 100644
--- a/frontend/tests/zone/zone-domain-selector.test.tsx
+++ b/frontend/tests/zone/zone-domain-selector.test.tsx
@@ -13,7 +13,7 @@ vi.mock('next/link', () => ({
}));
const zones: ZoneItem[] = [
- {id: 1, domain: 'arctel.de', created_at: '', updated_at: ''},
+ {id: 1, domain: 'example.com', created_at: '', updated_at: ''},
];
const domains: ZoneDomainItem[] = [
@@ -21,7 +21,7 @@ const domains: ZoneDomainItem[] = [
id: 7,
zone_id: 1,
proxy_route_id: null,
- domain: 'api.arctel.de',
+ domain: 'api.example.com',
cert_id: 9,
created_at: '',
updated_at: '',
@@ -30,7 +30,7 @@ const domains: ZoneDomainItem[] = [
id: 8,
zone_id: 1,
proxy_route_id: 99,
- domain: 'bound.arctel.de',
+ domain: 'bound.example.com',
cert_id: null,
created_at: '',
updated_at: '',
@@ -56,12 +56,12 @@ describe('ZoneDomainSelector', () => {
/>,
);
- expect(screen.getByText('api.arctel.de')).toBeVisible();
+ expect(screen.getByText('api.example.com')).toBeVisible();
// Bound to another route — hidden by default
- expect(screen.queryByText('bound.arctel.de')).not.toBeInTheDocument();
+ expect(screen.queryByText('bound.example.com')).not.toBeInTheDocument();
expect(screen.getByRole('button', {name: /快捷新增域名/})).toBeVisible();
- await user.click(screen.getByText('api.arctel.de'));
+ await user.click(screen.getByText('api.example.com'));
expect(onChange).toHaveBeenCalledWith([]);
});
@@ -76,8 +76,8 @@ describe('ZoneDomainSelector', () => {
/>,
);
- expect(screen.getByText('api.arctel.de')).toBeVisible();
- expect(screen.queryByText('bound.arctel.de')).not.toBeInTheDocument();
+ expect(screen.getByText('api.example.com')).toBeVisible();
+ expect(screen.queryByText('bound.example.com')).not.toBeInTheDocument();
});
it('still shows domains already bound to the current route', () => {
@@ -91,7 +91,7 @@ describe('ZoneDomainSelector', () => {
/>,
);
- expect(screen.getByText('bound.arctel.de')).toBeVisible();
- expect(screen.getByText('api.arctel.de')).toBeVisible();
+ expect(screen.getByText('bound.example.com')).toBeVisible();
+ expect(screen.getByText('api.example.com')).toBeVisible();
});
});
diff --git a/frontend/tests/zone/zone-page.test.tsx b/frontend/tests/zone/zone-page.test.tsx
index 0c6528ce..26950db1 100644
--- a/frontend/tests/zone/zone-page.test.tsx
+++ b/frontend/tests/zone/zone-page.test.tsx
@@ -14,6 +14,7 @@ class ResizeObserverMock {
vi.stubGlobal('ResizeObserver', ResizeObserverMock);
let mockZoneId = '42';
+let mockParamZoneId = '42';
const replaceMock = vi.fn();
@@ -27,7 +28,7 @@ vi.mock('next/navigation', () => ({
useRouter: () => ({replace: replaceMock, back: vi.fn()}),
usePathname: () => `/websites/${mockZoneId}`,
useSearchParams: () => new URLSearchParams(),
- useParams: () => ({zoneId: mockZoneId}),
+ useParams: () => ({zoneId: mockParamZoneId}),
}));
vi.mock('@/lib/services/openflare', async (importOriginal) => {
@@ -49,8 +50,9 @@ vi.mock('@/lib/services/openflare', async (importOriginal) => {
};
});
-function renderPage(zoneId: number) {
+function renderPage(zoneId: number, paramZoneId = zoneId) {
mockZoneId = String(zoneId);
+ mockParamZoneId = String(paramZoneId);
const client = new QueryClient({
defaultOptions: {
queries: {retry: false, gcTime: 0},
@@ -65,6 +67,7 @@ function renderPage(zoneId: number) {
describe('ZonePageClient', () => {
beforeEach(() => {
+ mockParamZoneId = mockZoneId;
vi.mocked(ZoneService.getOverview).mockReset();
vi.mocked(ZoneService.getStats).mockReset();
vi.mocked(ZoneService.getStats).mockResolvedValue({
@@ -89,7 +92,7 @@ describe('ZonePageClient', () => {
it('loads the overview by stable ID and exposes all tabs including empty domains', async () => {
vi.mocked(ZoneService.getOverview).mockImplementation(async () => ({
- zone: {id: 42, domain: 'arctel.de', created_at: '', updated_at: ''},
+ zone: {id: 42, domain: 'example.com', created_at: '', updated_at: ''},
domains: [],
}));
@@ -98,7 +101,7 @@ describe('ZonePageClient', () => {
await waitFor(() => {
expect(ZoneService.getOverview).toHaveBeenCalledWith(42);
});
- expect(await screen.findByRole('heading', {name: 'arctel.de'})).toBeVisible();
+ expect(await screen.findByRole('heading', {name: 'example.com'})).toBeVisible();
expect(await screen.findByText('唯一访问者')).toBeVisible();
expect(screen.getByText('请求总数')).toBeVisible();
expect(screen.getByText('已提供的数据总计')).toBeVisible();
@@ -108,6 +111,20 @@ describe('ZonePageClient', () => {
expect(screen.getByRole('tab', {name: '设置'})).toBeVisible();
});
+ it('uses the browser pathname ID when serving a static-export fallback shell', async () => {
+ vi.mocked(ZoneService.getOverview).mockImplementation(async () => ({
+ zone: {id: 42, domain: 'example.com', created_at: '', updated_at: ''},
+ domains: [],
+ }));
+
+ renderPage(42, 1);
+
+ await waitFor(() => {
+ expect(ZoneService.getOverview).toHaveBeenCalledWith(42);
+ });
+ expect(ZoneService.getOverview).not.toHaveBeenCalledWith(1);
+ });
+
it('renders a not-found state for a missing Zone', async () => {
vi.mocked(ZoneService.getOverview).mockRejectedValue(new Error('Zone 不存在'));
diff --git a/internal/router/root/frontend.go b/internal/router/root/frontend.go
index cd357d66..d5c329c8 100644
--- a/internal/router/root/frontend.go
+++ b/internal/router/root/frontend.go
@@ -101,7 +101,16 @@ func init() {
}
}
- // 4. 单页应用(SPA)前端路由兜底:返回 index.html
+ // 4. Next.js static export dynamic route fallback. Runtime IDs cannot be
+ // enumerated at build time, so serve the generated route shell instead of
+ // falling back to the dashboard index.html.
+ if fallbackPath, ok := resolveNextExportDynamicFallback(subFS, cleanPath); ok {
+ if serveFileDirect(c, subFS, fallbackPath) {
+ return
+ }
+ }
+
+ // 5. 单页应用(SPA)前端路由兜底:返回 index.html
if serveFileDirect(c, subFS, "index.html") {
return
}
diff --git a/internal/router/root/frontend_static.go b/internal/router/root/frontend_static.go
new file mode 100644
index 00000000..25f6b2d1
--- /dev/null
+++ b/internal/router/root/frontend_static.go
@@ -0,0 +1,34 @@
+// Copyright 2026 Arctel.net
+// SPDX-License-Identifier: Apache-2.0
+
+package root
+
+import (
+ "io/fs"
+ "strings"
+)
+
+//nolint:unused // Used by frontend.go in embed_frontend builds; default lint runs without that tag.
+func resolveNextExportDynamicFallback(subFS fs.FS, cleanPath string) (string, bool) {
+ parts := strings.Split(cleanPath, "/")
+ if len(parts) < 2 || parts[0] != "websites" || parts[1] == "" {
+ return "", false
+ }
+
+ var templatePath string
+ switch {
+ case len(parts) == 2 && !strings.Contains(parts[1], "."):
+ templatePath = "websites/1.html"
+ case len(parts) == 2 && strings.HasSuffix(parts[1], ".txt"):
+ templatePath = "websites/1.txt"
+ case len(parts) == 3 && parts[2] != "" && strings.HasPrefix(parts[2], "__next.") && strings.HasSuffix(parts[2], ".txt"):
+ templatePath = "websites/1/" + parts[2]
+ default:
+ return "", false
+ }
+
+ if _, err := fs.Stat(subFS, templatePath); err != nil {
+ return "", false
+ }
+ return templatePath, true
+}
diff --git a/internal/router/root/frontend_static_test.go b/internal/router/root/frontend_static_test.go
new file mode 100644
index 00000000..97b5a3d5
--- /dev/null
+++ b/internal/router/root/frontend_static_test.go
@@ -0,0 +1,74 @@
+// Copyright 2026 Arctel.net
+// SPDX-License-Identifier: Apache-2.0
+
+package root
+
+import (
+ "testing"
+ "testing/fstest"
+)
+
+func TestResolveNextExportDynamicFallbackUsesZoneTemplate(t *testing.T) {
+ subFS := fstest.MapFS{
+ "index.html": &fstest.MapFile{Data: []byte("dashboard")},
+ "websites/1.html": &fstest.MapFile{Data: []byte("zone detail")},
+ "websites/1.txt": &fstest.MapFile{Data: []byte("zone flight")},
+ "websites/1/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt": &fstest.MapFile{Data: []byte("zone segment")},
+ }
+
+ tests := []struct {
+ name string
+ input string
+ want string
+ }{
+ {name: "html", input: "websites/3", want: "websites/1.html"},
+ {name: "route payload", input: "websites/3.txt", want: "websites/1.txt"},
+ {
+ name: "segment payload",
+ input: "websites/3/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt",
+ want: "websites/1/__next.!KG1haW4p.websites.$d$zoneId.__PAGE__.txt",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, ok := resolveNextExportDynamicFallback(subFS, tt.input)
+ if !ok {
+ t.Fatal("expected dynamic websites route fallback")
+ }
+ if got != tt.want {
+ t.Fatalf("expected %q fallback, got %q", tt.want, got)
+ }
+ })
+ }
+}
+
+func TestResolveNextExportDynamicFallbackRejectsNestedOrAssetPath(t *testing.T) {
+ subFS := fstest.MapFS{
+ "websites/1.html": &fstest.MapFile{Data: []byte("zone detail")},
+ }
+
+ tests := []string{
+ "websites",
+ "websites/3/settings",
+ "websites/3.js",
+ "websites/3/",
+ "websites/3/missing.txt",
+ }
+ for _, tt := range tests {
+ t.Run(tt, func(t *testing.T) {
+ if got, ok := resolveNextExportDynamicFallback(subFS, tt); ok {
+ t.Fatalf("expected no fallback, got %q", got)
+ }
+ })
+ }
+}
+
+func TestResolveNextExportDynamicFallbackRequiresGeneratedTemplate(t *testing.T) {
+ subFS := fstest.MapFS{
+ "index.html": &fstest.MapFile{Data: []byte("dashboard")},
+ }
+
+ if got, ok := resolveNextExportDynamicFallback(subFS, "websites/3"); ok {
+ t.Fatalf("expected no fallback without generated template, got %q", got)
+ }
+}