From c4008f617dd6f04744d16b4c3cb72b9d924ab81a Mon Sep 17 00:00:00 2001 From: samanhappy Date: Fri, 18 Apr 2025 22:44:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20add=20catch-all=20route=20to=20serve=20f?= =?UTF-8?q?rontend=20index.html=20in=20AppServer=20in=E2=80=A6=20(#24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/index.ts | 5 ----- src/server.ts | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index 45e82cc..ade6197 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,6 +1,5 @@ import express from 'express'; import { check } from 'express-validator'; -import path from 'path'; import { getAllServers, getAllSettings, @@ -72,10 +71,6 @@ export const initRoutes = (app: express.Application): void => { ], changePassword); app.use('/api', router); - - app.get('*', (_req, res) => { - res.sendFile(path.join(process.cwd(), 'frontend', 'dist', 'index.html')); - }); }; export default router; diff --git a/src/server.ts b/src/server.ts index fcbe6c9..57a9739 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ import express from 'express'; import config from './config/index.js'; +import path from 'path'; import { initMcpServer } from './services/mcpService.js'; import { initMiddlewares } from './middlewares/index.js'; import { initRoutes } from './routes/index.js'; @@ -37,6 +38,11 @@ export class AppServer { .catch((error) => { console.error('Error initializing MCP server:', error); throw error; + }) + .finally(() => { + this.app.get('*', (_req, res) => { + res.sendFile(path.join(process.cwd(), 'frontend', 'dist', 'index.html')); + }); }); } catch (error) { console.error('Error initializing server:', error);