Docs for usage of a Plug.Router along side a custom handler
lilrooness opened this issue · comments
In order to handle WebSocket connections (or have any other custom cowboy2 handler) alongside using a Plug.Router to route other http requests, I have to manually configure Cowboy's dispatch using the :dispatch
option.
It's great that you have provided this option! 👍
However, it is only briefly referred to here and there is no mention of the Plug.Adapters.Cowboy.Handler
module which is necessary to configure Plug.Router manually. This makes me wonder if doing this is supported functionality?
It would be nice to have the example:
dispatch: [
{^hostname, [
{"/to_custom_handler", WebServerApp.CustomHandler, []},
{:_, Plug.Adapters.Cowboy.Handler, {WebServerApp.Router, []}}
]}
]
Thanks 😺 - PS The docs may very well already contain this, if so - my mistake 👍
It is not officially supported, which is why we don't talk about it extensively. In other words, if you decide to use it, there is no guarantee it will continue working in future versions in regards to accessing the handler directly - but it has been working like that for years. :)
Thanks for the clarification @josevalim :)