Skip to content

Commit bb0f553

Browse files
committed
fix: rutas hono
1 parent 77f5a1d commit bb0f553

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/app.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,22 @@ app.get('/assets/*', async (c) => {
6666
}
6767
});
6868

69-
// Fallback del SPA: cualquier otra ruta GET sirve index.html (router del lado cliente).
69+
// Fallback del SPA. Si la ruta tiene extensión (favicon, /roz.png y demás de web/public que
70+
// el build copia a dist), se sirve ese archivo; si no existe o no tiene extensión, cae al
71+
// index.html para que resuelva el router del lado cliente.
7072
app.get('*', async (c) => {
73+
const rel = c.req.path.replace(/^\/+/, '');
74+
if (rel && extname(rel)) {
75+
try {
76+
const buf = await readFile(join(SPA_DIST, rel));
77+
return c.body(buf, 200, {
78+
'content-type': MIME[extname(rel)] ?? 'application/octet-stream',
79+
'cache-control': 'public, max-age=3600',
80+
});
81+
} catch {
82+
/* no es un archivo del build: cae al SPA */
83+
}
84+
}
7185
try {
7286
return c.html(await readFile(join(SPA_DIST, 'index.html'), 'utf8'));
7387
} catch {

0 commit comments

Comments
 (0)