fix: add catch-all route to serve frontend index.html in AppServer in… (#24)

This commit is contained in:
samanhappy
2025-04-18 22:44:12 +08:00
committed by GitHub
parent 6a5039a90e
commit c4008f617d
2 changed files with 6 additions and 5 deletions

View File

@@ -1,6 +1,5 @@
import express from 'express'; import express from 'express';
import { check } from 'express-validator'; import { check } from 'express-validator';
import path from 'path';
import { import {
getAllServers, getAllServers,
getAllSettings, getAllSettings,
@@ -72,10 +71,6 @@ export const initRoutes = (app: express.Application): void => {
], changePassword); ], changePassword);
app.use('/api', router); app.use('/api', router);
app.get('*', (_req, res) => {
res.sendFile(path.join(process.cwd(), 'frontend', 'dist', 'index.html'));
});
}; };
export default router; export default router;

View File

@@ -1,5 +1,6 @@
import express from 'express'; import express from 'express';
import config from './config/index.js'; import config from './config/index.js';
import path from 'path';
import { initMcpServer } from './services/mcpService.js'; import { initMcpServer } from './services/mcpService.js';
import { initMiddlewares } from './middlewares/index.js'; import { initMiddlewares } from './middlewares/index.js';
import { initRoutes } from './routes/index.js'; import { initRoutes } from './routes/index.js';
@@ -37,6 +38,11 @@ export class AppServer {
.catch((error) => { .catch((error) => {
console.error('Error initializing MCP server:', error); console.error('Error initializing MCP server:', error);
throw error; throw error;
})
.finally(() => {
this.app.get('*', (_req, res) => {
res.sendFile(path.join(process.cwd(), 'frontend', 'dist', 'index.html'));
});
}); });
} catch (error) { } catch (error) {
console.error('Error initializing server:', error); console.error('Error initializing server:', error);