connections is of type _Request while request is of type Reply
raythurnvoid opened this issue · 1 comments
raythurnvoid commented
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.24.3
Plugin version
8.2.0
Node.js version
20.8.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
11
Description
I was struggling to get the query string from the request because the handler parameters don't match with what they are supposed to be according to the docs:
Steps to Reproduce
import Fastify from 'fastify';
import websocket from '@fastify/websocket';
import { WebSocket } from 'ws';
const fastify = Fastify();
fastify.register(websocket);
fastify.get('/chat', { websocket: true }, (connection, req) => {
try {
console.log(connection, req);
} catch (e) {
console.error(e);
}
});
fastify.listen({ port: 3000 }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server listening at: ${address}`);
});
const ws = new WebSocket('ws://localhost:3000/chat?username=test');
Expected Behavior
No response
raythurnvoid commented
Mi Bad, i had to wrap the ws handler in an additional fastify.register
. I was deceived by some outdated tutorial online.