Kazz
Kazz
Explore posts from servers
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
RIP my wallet. But yeah i guess Claude cant do this now, or at least on the free version. GPT did it without the "serach" enabled though it wasnt as accurate as the answer you got
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Interesting thet GPT could do it and not Claude
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
But AI's in general are not up to date with the latest Hono tech thats for sure
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
I dont think so, i rarely use GPT4
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Rewarding is one word for it
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
I'll mark this as solved for now
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Thanks! Now I have to go rewrite most of my code 👍
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Im blind
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
I looked for it, they only show for Deno and Bun and Cloudflare workers https://hono.dev/docs/helpers/websocket
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Lol i had no idea how many posts i will do xD
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
Is there a better way to allow Web socket to run with Hono without creating a server?
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
However this doesn't look like good code at all and I was expecting it to give me errors in the future. Which it did. I used Better-Auth with Hono and here is were my problems started showing. A lot of better auth functionalities got limited and some break because of this code. And I'm pretty sure later on other things will break because of this [3/3]
42 replies
HHono
Created by Kazz on 4/15/2025 in #help
Node Web Sockets in Hono
const httpServer = createServer(async (req, res) => {
try {
// Handle WebSocket upgrade requests separately
if (req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') return

// Convert Node.js request to Web standard Request
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`)
const headers = new Headers()
Object.entries(req.headers).forEach(([key, value]) => {
if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value)
})

const body = req.method !== 'GET' && req.method !== 'HEAD' ? req : null
// Create readable stream from request body
let bodyStream = null
if (body) {
bodyStream = new ReadableStream({
start(controller) {
body.on('data', chunk => controller.enqueue(chunk))
body.on('message', chunk => controller.enqueue(chunk))
body.on('end', () => controller.close())
body.on('error', err => controller.error(err))
},
})
}

const request = new Request(url.toString(), { method: req.method, headers, body: bodyStream })

const response = await app.fetch(request)

// Write the response back to the Node.js response object
res.writeHead(response.status, Object.fromEntries(response.headers.entries()))

const responseBody = await response.arrayBuffer()
res.end(Buffer.from(responseBody))
} catch (err) {
console.error('Error handling request:', err)
res.writeHead(500)
res.end('Internal Server Error')
}
})
const wss = new WebSocketServer({ server: httpServer, path: '/ws' })

serve({ fetch:app.fetch, port:config.PORT, createServer:()=>httpServer }, info => console.log(`💨 API server is running on Port ${info.port}`))
const httpServer = createServer(async (req, res) => {
try {
// Handle WebSocket upgrade requests separately
if (req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') return

// Convert Node.js request to Web standard Request
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`)
const headers = new Headers()
Object.entries(req.headers).forEach(([key, value]) => {
if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value)
})

const body = req.method !== 'GET' && req.method !== 'HEAD' ? req : null
// Create readable stream from request body
let bodyStream = null
if (body) {
bodyStream = new ReadableStream({
start(controller) {
body.on('data', chunk => controller.enqueue(chunk))
body.on('message', chunk => controller.enqueue(chunk))
body.on('end', () => controller.close())
body.on('error', err => controller.error(err))
},
})
}

const request = new Request(url.toString(), { method: req.method, headers, body: bodyStream })

const response = await app.fetch(request)

// Write the response back to the Node.js response object
res.writeHead(response.status, Object.fromEntries(response.headers.entries()))

const responseBody = await response.arrayBuffer()
res.end(Buffer.from(responseBody))
} catch (err) {
console.error('Error handling request:', err)
res.writeHead(500)
res.end('Internal Server Error')
}
})
const wss = new WebSocketServer({ server: httpServer, path: '/ws' })

serve({ fetch:app.fetch, port:config.PORT, createServer:()=>httpServer }, info => console.log(`💨 API server is running on Port ${info.port}`))
[2/3]
42 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
Marking this as solved as it's a problem made by me and not the library
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
I'll figure out how to allow better-auth to bypass this as well
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
It something I did and totally forgot about for Hono itself. I've changed the way the Hono serves the application by bypassing some stuff so that my socket works
const httpServer = createServer(async (req, res) => {
try {
// Handle WebSocket upgrade requests separately
if (req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') {
// Let the WebSocketServer handle this
return
}

// Convert Node.js request to Web standard Request
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`)
const headers = new Headers()
Object.entries(req.headers).forEach(([key, value]) => {
if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value)
})

const body = req.method !== 'GET' && req.method !== 'HEAD' ? req : null
// Create readable stream from request body
let bodyStream = null
if (body) {
bodyStream = new ReadableStream({
start(controller) {
body.on('data', chunk => controller.enqueue(chunk))
body.on('message', chunk => controller.enqueue(chunk))
body.on('end', () => controller.close())
body.on('error', err => controller.error(err))
},
})
}

const request = new Request(url.toString(), { method: req.method, headers, body: bodyStream })

const response = await app.fetch(request)

// Write the response back to the Node.js response object
res.writeHead(response.status, Object.fromEntries(response.headers.entries()))

const responseBody = await response.arrayBuffer()
res.end(Buffer.from(responseBody))
} catch (err) {
console.error('Error handling request:', err)
res.writeHead(500)
res.end('Internal Server Error')
}
})
const httpServer = createServer(async (req, res) => {
try {
// Handle WebSocket upgrade requests separately
if (req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket') {
// Let the WebSocketServer handle this
return
}

// Convert Node.js request to Web standard Request
const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`)
const headers = new Headers()
Object.entries(req.headers).forEach(([key, value]) => {
if (value) headers.set(key, Array.isArray(value) ? value.join(', ') : value)
})

const body = req.method !== 'GET' && req.method !== 'HEAD' ? req : null
// Create readable stream from request body
let bodyStream = null
if (body) {
bodyStream = new ReadableStream({
start(controller) {
body.on('data', chunk => controller.enqueue(chunk))
body.on('message', chunk => controller.enqueue(chunk))
body.on('end', () => controller.close())
body.on('error', err => controller.error(err))
},
})
}

const request = new Request(url.toString(), { method: req.method, headers, body: bodyStream })

const response = await app.fetch(request)

// Write the response back to the Node.js response object
res.writeHead(response.status, Object.fromEntries(response.headers.entries()))

const responseBody = await response.arrayBuffer()
res.end(Buffer.from(responseBody))
} catch (err) {
console.error('Error handling request:', err)
res.writeHead(500)
res.end('Internal Server Error')
}
})
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
I think i found the problem
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
Yes i removed it 😅
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
Without cache and secure cookies 1. The cookie gets set 2. On sign out it doesnt get deleted
28 replies
BABetter Auth
Created by Kazz on 4/15/2025 in #help
Sessions not working
despite them being deleted from the database
28 replies