mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 06:46:52 +00:00
fix(web): support static asset routing under Bun.serve and fix test types
This commit is contained in:
+21
-9
@@ -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',
|
||||
})
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user