afrad / angular2-websocket

Websocket wrapper for angular2 based on angular-websocket
Apache License 2.0
210 stars 84 forks source link

Proxy Websocket and global error handler #53

Open mburger81 opened 7 years ago

mburger81 commented 7 years ago

I know this is not a issue but I don't know how I can ask you something.

We are using your websocket in an ionic2 project and it's working great. There are three things we like to do. 1) we would like to proxy it like normal http requests, this for testing 2) we need a global point where we can configure the url to call, this for production 3) global error handling

this is how we implemented it for regular http requests 1) We configure a proxy in our ionic configuration for /api which is working only in dev mode so all HTTP requests where redirected and there is no CORS problem, we found no solution to proxy also Websockt requests. Do you have an idea=

2) We created a CustomHTTP Interceptor which is used instead of the regular HTTP, this checks if environment is dev or production, if dev we leave the url as it is, in dev mode means /api/ which will be redirect by proxy configuration, if we are in production I change the url to https.... or an other url, it depend if we are on a device or on a browser.

3) With this interceptor also we can handle http errors and log them.

So we need to do the same thing with your websocket implementation. Did you do something like that before? do you have some examples or some ideas to share with us? We can also open an stack-overflow to discuss this.!

thx for you help

afrad commented 7 years ago

Hi @mburger81, These are separates feature requests. I think it would be better they should be posted as new issues.

mburger81 commented 7 years ago

Hi @afrad yea this could be a feature request and for sure not a issue. I know, but here I can't open a feature request, or could I? I didn't found it.

My hope was, you could help us implementing this things or perhaps do you have already done some of this things in some of your projects, because I think it is not necessary implementing this, we could also resolve this using a dedicated service, observable or something like that.

mburger81 commented 7 years ago

Some news?

mburger81 commented 7 years ago

HI @afrad, I'm still waiting for some news about it. Where can I open you a feature request? How is it about including Websocket + webpack + http-proxy implementation for proxy a websocket call?

afrad commented 7 years ago

Just create PRs accordingly. We will merge them.

mburger81 commented 7 years ago

I think this FR doesn't make sense, because you never can proxy WebSocket like a http request doing something like that new WebSocket('/proxy/blabla/....'); because native WebSocket implementations check for the ws url which should start with ws:// or ws:// it would never work.

@afrad right?