fix(web): support static asset routing under Bun.serve and fix test types

This commit is contained in:
yiling
2026-06-03 23:30:33 +08:00
parent cf2e6907ba
commit 05f6069af7
2 changed files with 23 additions and 9 deletions
+21 -9
View File
@@ -9,6 +9,8 @@ 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()
@@ -43,17 +45,27 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
const server = Bun.serve({
port: 3000,
fetch: app.fetch,
routes: {
// Serve index.html for root
'/': index,
async fetch(req) {
const url = new URL(req.url)
const pathname = url.pathname
// Proxy API requests to Hono
'/api/*': app.fetch,
'/files/*': app.fetch,
if (pathname.startsWith('/api/') || pathname.startsWith('/files/')) {
return app.fetch(req)
}
// Catch-all for SPA routing (fallback to index.html)
'/*': index,
// 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 index as unknown as Response
},
development: process.env.NODE_ENV !== 'production',
})
+2
View File
@@ -204,6 +204,7 @@ describe('AgentService', () => {
avatar: avatarPresigned,
providerId: provider.id,
modelId: model.id,
thinkingLevel: 'medium',
})
expect(agent?.id).toBeDefined()
@@ -224,6 +225,7 @@ describe('AgentService', () => {
avatar: avatarPresigned,
providerId: agent.providerId!,
modelId: agent.modelId!,
thinkingLevel: 'medium',
})
expect(updated.user.image).toBe('files/01JK23456789ABCDEF01234567')