@@ -4,11 +4,19 @@ import express, { Request, Response } from 'express';
44import cors from 'cors' ;
55import { McpAnalytics } from '../src/index.js' ;
66import path from 'path' ;
7+ import { fileURLToPath } from 'url' ;
8+
9+ // Get the directory where this file is located
10+ const __filename = fileURLToPath ( import . meta. url ) ;
11+ const __dirname = path . dirname ( __filename ) ;
12+ const packageDir = path . resolve ( __dirname , '..' ) ;
713
814const app = express ( ) ;
915app . use ( cors ( ) ) ;
1016app . use ( express . json ( ) ) ;
11- app . use ( express . static ( path . join ( process . cwd ( ) , 'dist/web-viewer/public' ) ) ) ;
17+
18+ // Use the package directory instead of the current working directory
19+ app . use ( express . static ( path . join ( packageDir , 'web-viewer/public' ) ) ) ;
1220
1321// Get database path from command line args
1422let dbPath : string | undefined = undefined ;
@@ -74,7 +82,7 @@ app.get('/api/tools/daily', (_req: Request, res: Response) => {
7482// Add a fallback route to serve the index.html for any unknown routes
7583// This is necessary for client-side routing to work
7684app . get ( '*' , ( _req : Request , res : Response ) => {
77- res . sendFile ( path . join ( process . cwd ( ) , 'dist/ web-viewer/public/index.html' ) ) ;
85+ res . sendFile ( path . join ( packageDir , 'web-viewer/public/index.html' ) ) ;
7886} ) ;
7987
8088const port = process . env . PORT || 8080 ;
0 commit comments