Skip to content

fastify-websocket schema validation #102

@Extarys

Description

@Extarys

You have been so helpful in the past, so here I am.

I have a route that serve HTTP and websocket connections. It works great. I would like to use the build-in validator to validate the object received no matter if it's through http or websocket.

fastify.route({
        method: 'GET',
        url: '/v1/testhybrid',
        handler: (request, reply) => {
          myfunction("http", request, reply)
        },
        wsHandler: (conn, request) => {
          conn.setEncoding('utf8')
          // **message need validation**
          conn.socket.on('message', async message => {
            myfunction("ws", conn, request, message)
          })
 }})

I never really had to use ws before and I just started using schema validation in fastify. Tips are welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions