diff --git a/apps/web/src/index.ts b/apps/web/src/index.ts index 5175f53e..0b57405e 100644 --- a/apps/web/src/index.ts +++ b/apps/web/src/index.ts @@ -9,8 +9,6 @@ import { metadataService } from '@shumai/core/src/metadata/metadata' import { initTranscodeWorkflows } from '@shumai/transcode' import { workflowService } from '@shumai/workflow-core' import { app } from '@shumai/api' -import * as fs from 'fs' -import * as path from 'path' // Initialize workflows and activities for local executor mode initAgentWorkflows() @@ -45,27 +43,17 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') { const server = Bun.serve({ port: 3000, - async fetch(req) { - const url = new URL(req.url) - const pathname = url.pathname + fetch: app.fetch, + routes: { + // Serve index.html for root + '/': index, - if (pathname.startsWith('/api/') || pathname.startsWith('/files/')) { - return app.fetch(req) - } + // Proxy API requests to Hono + '/api/*': app.fetch, + '/files/*': app.fetch, - // Try serving from public folder - let publicFilePath = '' - if (pathname.startsWith('/public/')) { - publicFilePath = path.join(process.cwd(), 'packages/webui/public', pathname.substring(8)) - } else { - publicFilePath = path.join(process.cwd(), 'packages/webui/public', pathname) - } - - if (fs.existsSync(publicFilePath) && fs.statSync(publicFilePath).isFile()) { - return new Response(Bun.file(publicFilePath)) - } - - return new Response(index as unknown as BodyInit) + // Catch-all for SPA routing (fallback to index.html) + '/*': index, }, development: process.env.NODE_ENV !== 'production', })