fix(admin): handle /admin directory vs /admin/files correctly
/admin path (no trailing slash or ext) must serve admin.html SPA, /admin/dashboard.html must serve ./public/admin/dashboard.html. Previously /admin tried to read ./public/admin directory causing 500. Refs: production server
This commit is contained in:
@@ -1803,7 +1803,9 @@ app.get('/src/i18n/*', serveStatic({ root: '.' }))
|
||||
|
||||
// Admin HTML components - read file text explicitly to force Content-Length
|
||||
app.get('/admin/*', async (c) => {
|
||||
const filePath = `./public${c.req.path}`
|
||||
const path = c.req.path
|
||||
// If path ends with /, it's a directory → serve admin SPA
|
||||
const filePath = path.endsWith('/') ? './public/admin.html' : `./public${path}`
|
||||
const file = Bun.file(filePath)
|
||||
const text = await file.text()
|
||||
c.header('Content-Length', String(Buffer.byteLength(text, 'utf8')))
|
||||
|
||||
Reference in New Issue
Block a user