Last active
April 8, 2024 14:39
-
-
Save czfadmin/f5bffc10dd089aad6fd2052da5c456be to your computer and use it in GitHub Desktop.
honojs+socket.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { serve } from '@hono/node-server'; | |
| import { Hono } from 'hono'; | |
| import { Server } from 'socket.io'; | |
| import { Server as HttpServer } from 'http'; | |
| const app = new Hono(); | |
| app.get('/', (c) => { | |
| return c.text('Hello Hono!'); | |
| }); | |
| const server = serve( | |
| { | |
| fetch: app.fetch, | |
| port: 3000, | |
| }, | |
| (info) => { | |
| console.log(`Server is running: http://${info.address}:${info.port}`); | |
| } | |
| ); | |
| const ioServer = new Server(server as HttpServer, { | |
| path: '/ws', | |
| serveClient: false, | |
| }); | |
| ioServer.on("error", (err) => { | |
| console.log(err) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment