From 369b391136846b1d1d341c14b18984467b1bb020 Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Sun, 15 Jun 2025 17:55:52 -0400 Subject: [PATCH 1/3] fix(new-webui): Register React SPA routes in Fastify server; Fix path resolution for `rootDirname`. --- .../log-viewer-webui/server/settings.json | 6 ++--- .../src/fastify-v2/plugins/external/env.ts | 1 + .../server/src/routes/static.ts | 22 +++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/components/log-viewer-webui/server/settings.json b/components/log-viewer-webui/server/settings.json index ac3e244fa3..4e615a3cf2 100644 --- a/components/log-viewer-webui/server/settings.json +++ b/components/log-viewer-webui/server/settings.json @@ -10,9 +10,9 @@ "MongoDbStreamFilesCollectionName": "stream-files", "MongoDbSearchResultsMetadataCollectionName": "results-metadata", - "ClientDir": "../../client/dist", - "LogViewerDir": "../../yscope-log-viewer/dist", - "StreamFilesDir": "../../../../build/clp-package/var/data/streams", + "ClientDir": "../client/dist", + "LogViewerDir": "../yscope-log-viewer/dist", + "StreamFilesDir": "../../../build/clp-package/var/data/streams", "StreamTargetUncompressedSize": 134217728, "StreamFilesS3Region": null, "StreamFilesS3PathPrefix": null, diff --git a/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts b/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts index 96e9fd4133..2e4b7b62e0 100644 --- a/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts +++ b/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts @@ -65,6 +65,7 @@ export const autoConfig = { ".env", ".env.local", ], + override: true, }, // Source for the configuration data diff --git a/components/log-viewer-webui/server/src/routes/static.ts b/components/log-viewer-webui/server/src/routes/static.ts index 2c7ed4b6f8..46404f673a 100644 --- a/components/log-viewer-webui/server/src/routes/static.ts +++ b/components/log-viewer-webui/server/src/routes/static.ts @@ -8,6 +8,16 @@ import {FastifyPluginAsync} from "fastify"; import settings from "../../settings.json" with {type: "json"}; +/** + * Routes for serving static files in the React SPA client. + * This should be kept in sync with the client-side routes defined in `client/src/router.tsx`. + */ +const CLIENT_ROUTES = Object.freeze([ + "/ingest", + "/search", + "/streamFile", +]); + /** * Creates static files serving routes. * @@ -16,7 +26,7 @@ import settings from "../../settings.json" with {type: "json"}; const routes: FastifyPluginAsync = async (fastify) => { const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); - const rootDirname = path.resolve(dirname, "../.."); + const rootDirname = path.resolve(dirname, "../../../.."); let streamFilesDir = settings.StreamFilesDir; if (false === path.isAbsolute(streamFilesDir)) { @@ -25,6 +35,7 @@ const routes: FastifyPluginAsync = async (fastify) => { await fastify.register(fastifyStatic, { prefix: "/streams", root: streamFilesDir, + decorateReply: false, }); let logViewerDir = settings.LogViewerDir; @@ -48,12 +59,15 @@ const routes: FastifyPluginAsync = async (fastify) => { await fastify.register(fastifyStatic, { prefix: "/", root: clientDir, - decorateReply: false, + decorateReply: true, wildcard: false, }); - fastify.get("/streamFile", (_, reply) => { - reply.sendFile("index.html", clientDir); + // Serve the index.html file for all routes in the React SPA client. + CLIENT_ROUTES.forEach((route) => { + fastify.get(route, (_, reply) => { + reply.sendFile("index.html"); + }); }); } }; From 32eb36ebf3eadfe506a1c833aae0a5fd53d6a3ee Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Sun, 15 Jun 2025 18:12:59 -0400 Subject: [PATCH 2/3] revert unrelated changes --- .../server/src/fastify-v2/plugins/external/env.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts b/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts index 2e4b7b62e0..96e9fd4133 100644 --- a/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts +++ b/components/log-viewer-webui/server/src/fastify-v2/plugins/external/env.ts @@ -65,7 +65,6 @@ export const autoConfig = { ".env", ".env.local", ], - override: true, }, // Source for the configuration data From b7da097a19f9b8f72031d87357281c5da331e8ec Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Mon, 16 Jun 2025 12:01:20 -0400 Subject: [PATCH 3/3] fix(static): Simplify static file serving by removing hardcoded client routes; Serve index.html for all unmatched routes. --- .../server/src/routes/static.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/components/log-viewer-webui/server/src/routes/static.ts b/components/log-viewer-webui/server/src/routes/static.ts index 46404f673a..03a7ea303c 100644 --- a/components/log-viewer-webui/server/src/routes/static.ts +++ b/components/log-viewer-webui/server/src/routes/static.ts @@ -8,16 +8,6 @@ import {FastifyPluginAsync} from "fastify"; import settings from "../../settings.json" with {type: "json"}; -/** - * Routes for serving static files in the React SPA client. - * This should be kept in sync with the client-side routes defined in `client/src/router.tsx`. - */ -const CLIENT_ROUTES = Object.freeze([ - "/ingest", - "/search", - "/streamFile", -]); - /** * Creates static files serving routes. * @@ -63,11 +53,9 @@ const routes: FastifyPluginAsync = async (fastify) => { wildcard: false, }); - // Serve the index.html file for all routes in the React SPA client. - CLIENT_ROUTES.forEach((route) => { - fastify.get(route, (_, reply) => { - reply.sendFile("index.html"); - }); + // Serve index.html for all unmatched routes in the React Single Page Application (SPA). + fastify.get("/*", (_, reply) => { + reply.sendFile("index.html"); }); } };