Hono supports Socket.io? #1781
Replies: 3 comments 6 replies
-
Hi @PatricioPoncini , So I came across to this problem as well last week. But, if you take a look at hono import { Server } from 'socket.io'
import { Server as HttpServer } from 'http'
import { Hono } from 'hono'
const app = new Hono()
const server = serve(app)
const io = new Server(server as HttpServer) Note that the type cast depends on the option you pass to Hope this helps :) |
Beta Was this translation helpful? Give feedback.
-
Bun is not written this way. |
Beta Was this translation helpful? Give feedback.
-
@czfadmin May I ask how to use I don't know how to implement similar functions in hono. I implemented it in Express like this: // server.ts
import express from 'express'
import http from 'http'
const app = express()
const server = http.createServer(app)
const io = new Server(server, {
cors: {
origin: '*',
},
})
io.on('connection', (socket) => {
console.log('a user connected')
})
app.set('io', io)
app.use('/messages', authenticate, messageRouter) // messages.ts
import express from 'express'
const router = express.Router()
router.get('/', (
req: express.Request,
res: express.Response,
) => {
const io = req.app.get('io')
io.emit('message', 'hello1')
// ...
}) |
Beta Was this translation helpful? Give feedback.
-
Hello everyone, I would like to know if Hono supports Socket.io, as I want to set up a socket service with Socket.io but I'm having issues with the ServerType. Since Socket.io only accepts one of these types:
http.Server | HTTPSServer | Http2SecureServer | number
And when I start a server with Hono, it returns the type
ServerType
so the Socket.io library gives me problems because it does not accept that typing. Does anyone know how I can set up the server with Hono and pass it as an argument to Socket.io?Beta Was this translation helpful? Give feedback.
All reactions