-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Exposing a WebSocket Handler for embeded NATS servers #5392
base: main
Are you sure you want to change the base?
Conversation
There are more edge cases that this doesn't support, ideally the tradeoffs are valid if you understand them and need them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to get #4122 rebased here in the next few hours so @BlizzTom can see if it satisfies his requirements |
#4122 has been rebased. Looked forward to any feedback! |
The only issues I see of that other PR is that the http server is still controlled by the NATS server instance, rather than my own, and I am forced to use the I could be talked into being ok with that, it's more of a limitation of that PR, and I didn't even realize it existed. A use case that I have is that my application has pretty strict security access through a single port (443), and NATS sits behind that network boundary. The application uses NATS embedded to cluster some logic between nodes. The website uses websockets to communicate with the application API. Currently, I have to reverse proxy the websocket port back into While the work around hasn't been terrible, it's an extra step of complexity and a network hop. With the web server mux being quite complicated and not using |
I should probably clarify the statements above about the "the web server mux being quite complicated". There are a few things we set on the
The mux is really the least of the issues, as we could just route a specific path in our mux to use the |
@BlizzTom Ok, I think you have a compelling reason why you would not be able to use the other PR and need your own http server and handler. I have few comments/questions:
|
Thanks for that feedback @kozlovic, I will work on a test case for it, as well as seeing if I can figure out the I would need to check the On the testing front, the intended usage is from the |
@BlizzTom The As for a test, I wanted to at least see something like starting a NATS Server and create an http.Server and run it, passing the new function you have added, then a simple test that checks that a NATS client can connect:
If the connection succeeds, and knowing that the port is not a NATS Server port (neither normal client nor websocket), it will good enough for a basic test. Otherwise, using the low level test helpers (as in TestWSTLSVerifyAndMap) would be able to inspect an incoming INFO protocol. But there is no need since you won't have a way to influence this with the new function (HandleWebsocket) you want to add. But yes, say that if in the test the NATS Server does not have websocket{} defined and your http.Server uses TLS, and you connect the NATS client with |
When embedding a NATS server with a UI, in order to take advantage of the Web Socket connection on the same server, it was required that you made a reverse proxy to the web socket port.
This exposes a small handler without MQTT/LEAF node support for embedding scenarios.
Signed-off-by: Tom Anderson tanderson@blizzard.com