Mihai Andrei
Mihai Andrei
Explore posts from servers
HHono
Created by Mihai Andrei on 11/9/2024 in #help
Building HonoJS ts app
Hello guys! How do you usually build a hono nodejs app? I have a plain api that I see it is using tsx to run on dev, but it doesn't have any build step. I saw in the docs there is a suggestion of adding a "build" step with tsc but i was curious how other people handle it Thank you!
1 replies
DTDrizzle Team
Created by Mihai Andrei on 11/3/2024 in #help
Drizzle better-sqlite3 WAL mode
Hello! Sorry if this was asked before but I couldn’t find a way to do it by searching. How should you enable WAL mode with drizzle? Is it enough to put it inside a migration file, or you need to somehow execute it when you connect
1 replies
HHono
Created by Mihai Andrei on 8/8/2024 in #help
Server Sent Events
Hello guys! Sorry if this was asked before. I'm trying to implement an event emitter with SSE like this:
const emitter = new EventEmitter();

app.use("/sse/*", async (c, next) => {
c.header("Content-Type", "text/event-stream");
c.header("Cache-Control", "no-cache");
c.header("Connection", "keep-alive");
await next();
});

app.post('/message', async (c) => {
const message = 'test';
emitter.emit('message', message);
return c.json({message});
})

app.get('/sse', async (c) => {
return streamSSE(c, async (stream) => {

const handler = async (message: string) => {
await stream.writeSSE({
data: message,
event: "message"
});
}

stream.onAbort(() => {
console.log('Connection aborted');
})

emitter.on('message', handler);
})
})
const emitter = new EventEmitter();

app.use("/sse/*", async (c, next) => {
c.header("Content-Type", "text/event-stream");
c.header("Cache-Control", "no-cache");
c.header("Connection", "keep-alive");
await next();
});

app.post('/message', async (c) => {
const message = 'test';
emitter.emit('message', message);
return c.json({message});
})

app.get('/sse', async (c) => {
return streamSSE(c, async (stream) => {

const handler = async (message: string) => {
await stream.writeSSE({
data: message,
event: "message"
});
}

stream.onAbort(() => {
console.log('Connection aborted');
})

emitter.on('message', handler);
})
})
but it seems it goes directly in the onError on frontend because it closes the stream
4 replies