Skip to content

A modern and elegant dashboard for network traffic visualization and analysis.

refactor: update manifest file path and enhance WebSocket URL candidate discovery.

luolei5197bc984b13
diff --git a/apps/web/app/[locale]/layout.tsx b/apps/web/app/[locale]/layout.tsx
index fc995df..136787d 100644
--- a/apps/web/app/[locale]/layout.tsx
+++ b/apps/web/app/[locale]/layout.tsx
@@ -62,7 +62,7 @@ export default async function RootLayout({
return (
<html lang={locale} suppressHydrationWarning>
<head>
- <link rel="manifest" href="/manifest.json" />
+ <link rel="manifest" href="/manifest.webmanifest" />
<link rel="apple-touch-icon" href="/icons/icon-192x192.png" />
<meta name="mobile-web-app-capable" content="yes" />
diff --git a/apps/web/lib/websocket.ts b/apps/web/lib/websocket.ts
index 7658d12..5df3c8d 100644
--- a/apps/web/lib/websocket.ts
+++ b/apps/web/lib/websocket.ts
@@ -81,17 +81,48 @@ function normalizeWsUrl(rawUrl: string, runtime?: RuntimeConfig): string {
function getWsUrlCandidates(): string[] {
const runtime = getRuntimeConfig();
const wsPort = runtime?.WS_PORT || process.env.NEXT_PUBLIC_WS_PORT || '3002';
- if (runtime?.WS_URL) return [normalizeWsUrl(runtime.WS_URL, runtime)];
- if (process.env.NEXT_PUBLIC_WS_URL) return [normalizeWsUrl(process.env.NEXT_PUBLIC_WS_URL, runtime)];
+
+ const configuredUrls = [
+ runtime?.WS_URL,
+ process.env.NEXT_PUBLIC_WS_URL,
+ ]
+ .map((value) => value?.trim())
+ .filter((value): value is string => !!value)
+ .map((value) => normalizeWsUrl(value, runtime))
+ .filter(Boolean);
+
+ const uniqueCandidates: string[] = [];
+ const pushCandidate = (url: string) => {
+ if (!url || uniqueCandidates.includes(url)) return;
+ uniqueCandidates.push(url);
+ };
+
+ for (const url of configuredUrls) {
+ pushCandidate(url);
+ }
+
if (typeof window !== 'undefined') {
const wsProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const hostForPort = runtime?.WS_HOST || window.location.hostname;
const directUrl = `${wsProtocol}://${hostForPort}:${wsPort}`;
const hostForPath = runtime?.WS_HOST || window.location.host;
const pathUrl = `${wsProtocol}://${hostForPath}/_cm_ws`;
- return [pathUrl, directUrl];
+
+ // Local development usually has no reverse proxy for /_cm_ws.
+ const preferDirect = process.env.NODE_ENV === 'development';
+ if (preferDirect) {
+ pushCandidate(directUrl);
+ pushCandidate(pathUrl);
+ } else {
+ pushCandidate(pathUrl);
+ pushCandidate(directUrl);
+ }
+
+ return uniqueCandidates;
}
- return [`ws://localhost:${wsPort}`];
+
+ pushCandidate(`ws://localhost:${wsPort}`);
+ return uniqueCandidates;
}
export function useStatsWebSocket(options: UseStatsWebSocketOptions = {}) {
diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts
index 85f7f14..43d01fa 100644
--- a/apps/web/next.config.ts
+++ b/apps/web/next.config.ts
@@ -38,6 +38,10 @@ const nextConfig: NextConfig = {
},
async rewrites() {
return [
+ {
+ source: "/manifest.json",
+ destination: "/manifest.webmanifest",
+ },
{
source: "/api/:path*",
destination: API_DESTINATION,