[node-ws] Upgrades every path to ws
Only defined paths should be upgraded to websocket connection, others should be immediately dropped.
+1
Hey @yusukebe, I noticed you have recently worked on node-ws package. Could you please look at this issue?
I only fixed the type definition. I'd like @nakasyou to take a look.
Sorry, I can't understand the topic well.
@iSuslov
Can you explain the problem and provide how we can reproduce it?
@yusukebe sure, here is a simple websocket server:
import { serve } from '@hono/node-server';
import { createNodeWebSocket } from '@hono/node-ws';
import { Hono } from 'hono';
const app = new Hono();
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
app.get(
'/ws',
upgradeWebSocket((c) => ({
onOpen(_event, ws) {
console.log('opened');
ws.send(new Date().toString());
},
onClose() {
console.log('closed');
},
})),
);
const port = 3010;
console.log(`Server is running on http://localhost:${port}`);
const server = serve({ ...app, port });
injectWebSocket(server);
- In a browser console create a new connection:
new WebSocket('ws://localhost:3010/ws').
All works as expected.
- Now try with undeclared path:
new WebSocket('ws://localhost:3010/unknown_path'):
As you can see, instead of rejecting the request to undeclared path, it upgrades it to websocket connection and keeps it alive.
It should accept websocket connections only on defined paths.
@iSuslov Sorry for the late reply. Thank you.
Hey @nakasyou Can you investigate it?
Wasn't resolved with https://github.com/honojs/middleware/pull/973?
@nakasyou Thanks! Exactly. I've tried to reproduce it, and the latest version works fine.
@iSuslov Can you close this issue?