NightFuries
NightFuries
HHono
Created by NightFuries on 9/5/2024 in #help
How to keep SSE alive with PSQL?
This is how it looks like in express (From ChatGPT). Here, the route waits for the connection to close and then it ends the response. How can i do something similar?
// SSE Endpoint to send logs to clients
app.get('/logs', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');

const sendLog = (log) => {
res.write(`data: ${JSON.stringify(log)}\n\n`);
};

pgClient.on('notification', (msg) => {
const payload = JSON.parse(msg.payload);
sendLog(payload); // Send the log to the client via SSE
});

req.on('close', () => {
res.end();
});
});
// SSE Endpoint to send logs to clients
app.get('/logs', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');

const sendLog = (log) => {
res.write(`data: ${JSON.stringify(log)}\n\n`);
};

pgClient.on('notification', (msg) => {
const payload = JSON.parse(msg.payload);
sendLog(payload); // Send the log to the client via SSE
});

req.on('close', () => {
res.end();
});
});
3 replies
HHono
Created by FlyCreat1ve on 9/4/2024 in #help
Bun + Hono doesn't work for me.
mark this as solved then 🙂
3 replies
HHono
Created by Glen Kurio on 8/17/2024 in #help
How to separate code into files for each handler without loosing the hono RPC typesafety?
I'm doing exactly the same thing. I don't really care if the single auth routes file is going over 400+ lines of code,
const auth = factory
.createApp()
.get('/', c => ...)
.post('/', c => ...)
.put('/', c => ...)
.delete('/', c => ...)
....

export default auth;

// index.ts
import auth from './auth'

const server = factory
.createApp()
.route('/auth', auth)
const auth = factory
.createApp()
.get('/', c => ...)
.post('/', c => ...)
.put('/', c => ...)
.delete('/', c => ...)
....

export default auth;

// index.ts
import auth from './auth'

const server = factory
.createApp()
.route('/auth', auth)
If you still want to separate out the routes within the auth "module", you could:
// loginUser.ts
export default factory
.createApp()
.post('/', ...)

// getUser.ts

export default factory
.createApp()
.get('/', ...)

// and then:

export default factory
.createApp()
.route('/', loginUser)
.route('/', getUser)

// and then route that to /auth in the main file.
// loginUser.ts
export default factory
.createApp()
.post('/', ...)

// getUser.ts

export default factory
.createApp()
.get('/', ...)

// and then:

export default factory
.createApp()
.route('/', loginUser)
.route('/', getUser)

// and then route that to /auth in the main file.
Disclaimer I haven't actually tested if it works, but that seems to be the most logical way in my head. LMK if it actually worked.
2 replies