New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket Helper not working #2645
Comments
Hi @mathysth |
Hey @nakasyou here the full code that you ask boostrapApp().then((httpConfig) => {
const logger = IocContainer.container.get(LoggerService);
const controllerRoot = IocContainer.container.get(ControllerRoot);
const socket = IocContainer.container.get(SocketProvider);
try {
serve({
async fetch(req, server) {
const serverConfig = await httpConfig?.fetch(req, { ip: server.requestIP(req) });
return serverConfig;
},
websocket,
port: httpConfig?.port,
});
// Initialize the socket
socket.initSocket();
// Setup all controllers
controllerRoot.setup();
logger.pino.info(`Hono 🥟 Server Listening on port ${httpConfig?.port}`);
} catch (e) {
logger.pino.error(`An error occurred during server initialization, ${e}`);
}
}); |
@nakasyou I found the problem but I'm still searching for the anwser. const app = new Hono()
serve({
fetch: (req, server) => {
return app.fetch(req, { ip: server.requestIP(req) })
},
websocket,
port: 3008,
}); But when you bind the ip as an env I think the server is not initialize... and then the websocket logic doesn't work anymore. |
@mathysth, this may also be a problem with Hono. As a workaround, you can use that: await httpConfig?.fetch(req, { upgrade: server.upgrade }) or await httpConfig?.fetch(req, server) |
@nakasyou I did this workaround, it's working, hope hono could fix this somedays. Thanks again serve({
async fetch(req, server) {
const untypedServer = server as unknown as any
untypedServer.ip = server.requestIP(req)
const serverConfig = await httpConfig?.fetch(req, untypedServer);
return serverConfig;
},
websocket,
port: httpConfig?.port,
}); |
What version of Hono are you using?
4.1.1
What runtime/platform is your app running on?
Bun
What steps can reproduce the bug?
I'm using Hono websocket helper but it return me and error when I try to connect to it
I cheked if my setup was good and for me it was
Here how I setup the ws to hono
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: