Skip to content

Conversation

@fox1t
Copy link
Member

@fox1t fox1t commented May 15, 2019

This PR adds support for routing to this plugin. Uses:

  • find-my-way
  • internal fastify router
  • adds all tests case needed

All the old functionalities are still working.

@fox1t fox1t mentioned this pull request May 15, 2019
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you restore the previous linting? We use standard with no semicolons. The same applies to README.

Also, can you split the test file? I think it's getting too big.

Copy link
Member

@darkgl0w darkgl0w left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, really nice feature ^^

As a side note, maybe we should also add a note that for asynchronous operations inside of an EventListener it is better to use a Promise with preferably a .catch() and a .finally() on compatible environments to avoid any potential memory leaks when something goes wrong (using async/await within .on('listener') isn't a good idea basically).

Co-Authored-By: Andrew Wong <andrew12345@live.com>
@mcollina
Copy link
Member

Can you please bump the dependency to Fastify v2.4.1? That has the fix you need.

@fox1t
Copy link
Member Author

fox1t commented May 22, 2019

OK, I’ll do ASAP!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this setup:

fastify.register(require('./'), {
  handle,
  options: { maxPayload: 1048576 }
})

fastify.get('/', { websocket: true }, (connection, req) => {
  connection.socket.on('message', message => {
    // message === 'hi from client'
    connection.socket.send('hi from server')
  })
})

Should we throw an error?

Co-Authored-By: Manuel Spigolon <behemoth89@gmail.com>
@fox1t
Copy link
Member Author

fox1t commented May 25, 2019

with this setup:

fastify.register(require('./'), {
  handle,
  options: { maxPayload: 1048576 }
})

fastify.get('/', { websocket: true }, (connection, req) => {
  connection.socket.on('message', message => {
    // message === 'hi from client'
    connection.socket.send('hi from server')
  })
})

Should we throw an error?

I don't understand your point. Can you elaborate, please?

Co-Authored-By: Manuel Spigolon <behemoth89@gmail.com>
@Eomm
Copy link
Member

Eomm commented May 25, 2019

I don't understand your point. Can you elaborate, please?

Yeah sorry.

In that case, I set up a global handler and a route handler at the same endpoint.

The server starts correctly and when I connect to it with const ws = new WebSocket('ws://localhost:3000') (also with the final slash) I will get a hi from server response.

So I'm wondering if it the case to throw an "already declared" error. WDYT?

@fox1t
Copy link
Member Author

fox1t commented May 25, 2019

WDYT

OK. I think there is a misconception about "global" handler: it is a handler that is called when no more specific routes are defined. If you don't defined it, the plugin provides the "404 WS" response for you. I think that what you did is the correct behavior.

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read better the docs and it is written, thank you for the explanation.

As you pointed I suggested the spaces

Great feature 👍 Thank you

fox1t and others added 2 commits May 25, 2019 15:06
Co-Authored-By: Manuel Spigolon <behemoth89@gmail.com>
@fox1t
Copy link
Member Author

fox1t commented May 25, 2019

I read better the docs and it is written, thank you for the explanation.

As you pointed I suggested the spaces

Great feature 👍 Thank you

Nice! ☺️

@fox1t
Copy link
Member Author

fox1t commented May 26, 2019

Snap, there is a conflict in README. @Eomm could you reslove it? Just use your suggestion.

@fox1t
Copy link
Member Author

fox1t commented May 31, 2019

Any news on merging this?

@Eomm Eomm merged commit 6f776a0 into fastify:master Jun 1, 2019
@Eomm
Copy link
Member

Eomm commented Jun 1, 2019

Releasing later today or at least tomorrow if anybody can't do it before 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants