mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 01:57:32 +08:00
33 lines
621 B
Go
33 lines
621 B
Go
package handlers
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/yhat/wsutil"
|
|
)
|
|
|
|
func NewMultipleHostWebsocketReverseProxy() *wsutil.ReverseProxy {
|
|
tlsConfig := &tls.Config{
|
|
InsecureSkipVerify: true,
|
|
}
|
|
director := func(req *http.Request) {
|
|
v := mux.Vars(req)
|
|
|
|
node, port := getTargetInfo(v, req)
|
|
|
|
if port == "443" {
|
|
// Only proxy http for now
|
|
req.URL.Scheme = "wss"
|
|
} else {
|
|
// Only proxy http for now
|
|
req.URL.Scheme = "ws"
|
|
}
|
|
req.URL.Host = fmt.Sprintf("%s:%s", node, port)
|
|
}
|
|
|
|
return &wsutil.ReverseProxy{Director: director, TLSClientConfig: tlsConfig}
|
|
}
|