Skip to content

Commit 234cfeb

Browse files
committed
Add manual asset handler to serve static files in HonoServerPlugin
1 parent 9d38d40 commit 234cfeb

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

apps/console/objectstack.config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,28 @@ class PatchedHonoServerPlugin extends HonoServerPlugin {
5959
const fs = require('fs');
6060
const path = require('path');
6161

62+
// Manual Asset Handler to ensure assets are served
63+
app.get('/assets/*', async (c: any) => {
64+
const filePath = path.join(path.resolve(staticRoot), c.req.path);
65+
if (fs.existsSync(filePath)) {
66+
const ext = path.extname(filePath);
67+
let contentType = 'application/octet-stream';
68+
if (ext === '.css') contentType = 'text/css';
69+
else if (ext === '.js') contentType = 'application/javascript';
70+
else if (ext === '.json') contentType = 'application/json';
71+
else if (ext === '.png') contentType = 'image/png';
72+
else if (ext === '.svg') contentType = 'image/svg+xml';
73+
74+
const content = fs.readFileSync(filePath);
75+
return c.body(content, 200, { 'Content-Type': contentType });
76+
}
77+
return c.text('Asset Not Found', 404);
78+
});
79+
6280
// Register fallback after serveStatic (which is added in listen/originalStart)
6381
app.get('*', async (c: any) => {
6482
// Ignore API calls -> let them 404
65-
if (c.req.path.startsWith('/api') || c.req.path.startsWith('/assets')) {
83+
if (c.req.path.startsWith('/api')) {
6684
return c.text('Not Found', 404);
6785
}
6886

0 commit comments

Comments
 (0)