Mihai Andrei
Mihai Andrei
Explore posts from servers
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