-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Full declaration syntax is not typed correctly for websocket: true
#314
Comments
Not tested yet.
From your example, it is expected behavior because |
I am facing this issue too. Even when I make a WebSocket request, the {
method: 'GET',
url: '/ws/logs',
wsHandler: (socket, request) => {
console.log('WS'); // This is never printed
},
handler: (socket, request) => {
console.log(socket.constructor.name);
// Prints "_Request" when executing "new WebSocket('ws://localhost:3000/ws/logs')" in the browser
},
} My route is defined using the full declaration syntax. Anything I’m missing? |
Nah, same here. Something is wrong, it always hits |
Ok, this is probably caused by a separate issue. You can do this and it will work: import Fastify from 'fastify';
import FastifyWebsocket from '@fastify/websocket';
const app = Fastify();
app.register(FastifyWebsocket);
app.register(async function (app) {
app.route({
method: 'GET',
url: '/',
wsHandler: (socket, request) => {
console.log('WS'); // not printed
},
handler: (socket, request) => {
console.log(socket.constructor.name === 'WebSocket'); // prints true (when executing "new WebSocket('ws://localhost:3000/')" in the browser)
},
});
}) |
Prerequisites
Fastify version
5.2.0
Plugin version
11.0.1
Node.js version
22.12
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Sonoma 14.5
Description
It seems that the full declaration syntax is not supported by
@fastify/websocket
types.Also, when the
wsHandler
property is set, the behaviour is the following:handler
property is still required and typescript throws error when it is not in place;handler
property is also set, the ws connection is handled by thehandler
property whilewsHandler
is ignored.Is this the expected behaviour?
Somewhat related issue: #133
Expected Behavior
RouteOptions
type) is typed correctly.handler
andwsHandler
are defined.The text was updated successfully, but these errors were encountered: