Streaming in Honox
Hi Guys,
I am trying to use streaming in a honox.js app.
When navigating
Not sure why this happens when the stream.ts is in the routes folder ?
Does honox.js work with streaming ? If it does how to use streaming or even streaming sse in honox.js ?
I am trying to use streaming in a honox.js app.
// routes/_renderer.tsx
import { jsxRenderer } from 'hono/jsx-renderer'
import { Link, Script } from 'honox/server'
export default jsxRenderer(({ children }) => {
return (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<title>Hono + htmx</title>
<Link href="/app/site.css" rel="stylesheet" />
<script type="module" src="/datastar1b11.js"></script>
<Script src="/app/client.ts" async />
</head>
<body>{children}</body>
</html>
)
},{ stream: true }
)
// routes/stream.ts
import { Hono } from 'hono';
import { stream } from 'hono/streaming';
const app = new Hono();
app.get('/stream', (c) => {
return stream(c, async (stream) => {
await stream.write("Loading...\n");
for (let i = 1; i <= 5; i++) {
await stream.sleep(1000); // Simulate delay
await stream.write(`Update ${i}\n`);
}
});
});
export default app// routes/_renderer.tsx
import { jsxRenderer } from 'hono/jsx-renderer'
import { Link, Script } from 'honox/server'
export default jsxRenderer(({ children }) => {
return (
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<title>Hono + htmx</title>
<Link href="/app/site.css" rel="stylesheet" />
<script type="module" src="/datastar1b11.js"></script>
<Script src="/app/client.ts" async />
</head>
<body>{children}</body>
</html>
)
},{ stream: true }
)
// routes/stream.ts
import { Hono } from 'hono';
import { stream } from 'hono/streaming';
const app = new Hono();
app.get('/stream', (c) => {
return stream(c, async (stream) => {
await stream.write("Loading...\n");
for (let i = 1; i <= 5; i++) {
await stream.sleep(1000); // Simulate delay
await stream.write(`Update ${i}\n`);
}
});
});
export default appWhen navigating
/stream/stream I land on a 404 page not found error.Not sure why this happens when the stream.ts is in the routes folder ?
Does honox.js work with streaming ? If it does how to use streaming or even streaming sse in honox.js ?