Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ function fastifyWebsocket (fastify, opts, next) {
isWebsocketRoute = true

if (routeOptions.websocket) {
if (!routeOptions.schema) {
routeOptions.schema = {}
}
routeOptions.schema.hide = true

wsHandler = routeOptions.handler
handler = function (_, reply) {
reply.code(404).send()
Expand Down
7 changes: 5 additions & 2 deletions test/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ const WebSocket = require('ws')
const split = require('split2')

test('Should run onRequest, preValidation, preHandler hooks', (t, end) => {
t.plan(7)
t.plan(8)
const fastify = Fastify()

t.after(() => fastify.close())

fastify.register(fastifyWebsocket)

fastify.register(async function (fastify) {
fastify.addHook('onRequest', async () => t.assert.ok('called', 'onRequest'))
fastify.addHook('onRequest', async ({ routeOptions: { schema: { hide } } }) => {
t.assert.ok('called', 'onRequest')
t.assert.strictEqual(hide, true, 'schema hide property should be set to true when route option is websocket')
})
fastify.addHook('preParsing', async () => t.assert.ok('called', 'preParsing'))
fastify.addHook('preValidation', async () => t.assert.ok('called', 'preValidation'))
fastify.addHook('preHandler', async () => t.assert.ok('called', 'preHandler'))
Expand Down