mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +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 { initTranscodeWorkflows } from '@shumai/transcode'
|
||||||
import { workflowService } from '@shumai/workflow-core'
|
import { workflowService } from '@shumai/workflow-core'
|
||||||
import { app } from '@shumai/api'
|
import { app } from '@shumai/api'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
|
||||||
// Initialize workflows and activities for local executor mode
|
// Initialize workflows and activities for local executor mode
|
||||||
initAgentWorkflows()
|
initAgentWorkflows()
|
||||||
@@ -43,17 +45,27 @@ if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
|
|||||||
|
|
||||||
const server = Bun.serve({
|
const server = Bun.serve({
|
||||||
port: 3000,
|
port: 3000,
|
||||||
fetch: app.fetch,
|
async fetch(req) {
|
||||||
routes: {
|
const url = new URL(req.url)
|
||||||
// Serve index.html for root
|
const pathname = url.pathname
|
||||||
'/': index,
|
|
||||||
|
|
||||||
// Proxy API requests to Hono
|
if (pathname.startsWith('/api/') || pathname.startsWith('/files/')) {
|
||||||
'/api/*': app.fetch,
|
return app.fetch(req)
|
||||||
'/files/*': app.fetch,
|
}
|
||||||
|
|
||||||
// Catch-all for SPA routing (fallback to index.html)
|
// Try serving from public folder
|
||||||
'/*': index,
|
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',
|
development: process.env.NODE_ENV !== 'production',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ describe('AgentService', () => {
|
|||||||
avatar: avatarPresigned,
|
avatar: avatarPresigned,
|
||||||
providerId: provider.id,
|
providerId: provider.id,
|
||||||
modelId: model.id,
|
modelId: model.id,
|
||||||
|
thinkingLevel: 'medium',
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(agent?.id).toBeDefined()
|
expect(agent?.id).toBeDefined()
|
||||||
@@ -224,6 +225,7 @@ describe('AgentService', () => {
|
|||||||
avatar: avatarPresigned,
|
avatar: avatarPresigned,
|
||||||
providerId: agent.providerId!,
|
providerId: agent.providerId!,
|
||||||
modelId: agent.modelId!,
|
modelId: agent.modelId!,
|
||||||
|
thinkingLevel: 'medium',
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(updated.user.image).toBe('files/01JK23456789ABCDEF01234567')
|
expect(updated.user.image).toBe('files/01JK23456789ABCDEF01234567')
|
||||||
|
|||||||
Reference in New Issue
Block a user