smarterclayton / openshift-go-cart

Go cartridge for OpenShift Origin
Other
75 stars 92 forks source link

Websocket port 443 for WSS:// #39

Open TaiPhamD opened 8 years ago

TaiPhamD commented 8 years ago

What can we do in go to be able to accept port 443 requests when to load balancer will forward all data at the OPENSHIFT_GO_PORT (8080). Most of the websocket libs will reject if it detects that the client doesn't come in at port 443.

AlexDias79 commented 7 years ago

Hello, Openshift uses a different port for WS and WSS,

WS is on port 8000 WSS is on port 8443 (uses openshift ssl certificates, even if your application doesn't have any certificate) Been using it just fine that way :)

siredwin commented 7 years ago

@AlexDias79 , you just did a redirect using that port and all just worked? Or, did you have to do something else too? I am also trying to accomplish the same thing.

AlexDias79 commented 7 years ago

Nop, no redirection needed. All i did was to inject a wss route into http router. Such as:


bind := fmt.Sprintf("%s:%s", os.Getenv("OPENSHIFT_GO_IP"), os.Getenv("OPENSHIFT_GO_PORT")) 
...
http.Handle("/wsInfos", websocket.Handler(infosWSHandler))
log.Fatalln(http.ListenAndServe(bind, nil))
 func infosWSHandler(ws *websocket.Conn) {
    Auth := ws.Request().URL.Query().Get("Authorization")
    if Auth != ApiKey {
        ws.Write([]byte("Authorization failed! Provided key was: " + Auth))
        return
    }
    ws.Write([]byte("Subscribed OK"))
    ch := msgBrokerInfos.Subscribe() //nothing more than a redis subscription
    defer msgBrokerInfos.Unsubscribe(ch)

So, when you use a ws or a wss into the openshift public url, the traffic will be correctly redirected as the server detects the protocol format. You don't need to define a port different than 80 for ws/wss, the openshift router itself will do that for you, for free :D

Hope it did help, Alex