Skip to content
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

fastify-websocket schema validation #102

Closed
Extarys opened this issue Sep 7, 2019 · 4 comments
Closed

fastify-websocket schema validation #102

Extarys opened this issue Sep 7, 2019 · 4 comments
Labels

Comments

@Extarys
Copy link

Extarys commented Sep 7, 2019

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.

@mcollina
Copy link
Member

mcollina commented Sep 7, 2019

That would be an handy feature for fastify-websocket, would you like to send a PR?

@Extarys
Copy link
Author

Extarys commented Sep 7, 2019

I would love to but my lack of knowledge would make it so it'll be available in a year :P
Can I access the AJV instance from fastify and plug my message object in the schema?

@mcollina
Copy link
Member

mcollina commented Sep 8, 2019

You should be able to access the schema definition (what is passed to the route) in https://github.com/fastify/fastify-websocket/blob/462d5510b8e7aa22e6e9bd62a718fa2791534e51/index.js#L29. I'm not sure who a the actual validator for the route could become available to a websocket.

@stale
Copy link

stale bot commented Sep 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants