mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 01:57:32 +08:00
Allow to send subdomains but forward header as is to backends
This commit is contained in:
parent
9e57f3b61c
commit
0df09bebdb
@ -37,7 +37,7 @@ Start the Docker daemon on your machine and run `docker pull franela/dind`.
|
||||
|
||||
3) Start PWD as a container with docker-compose up.
|
||||
|
||||
5) Point to http://localhost:3000/ and click "New Instance"
|
||||
5) Point to http://localhost and click "New Instance"
|
||||
|
||||
Notes:
|
||||
|
||||
@ -54,3 +54,7 @@ Notes:
|
||||
|
||||
If you need to access your services from outside, use the following URL pattern `http://pwd<underscore_ip>-<port>.play-with-docker.com` (i.e: http://pwd10_2_135_3-80.play-with-docker.com/).
|
||||
|
||||
### Why is PWD running in ports 80 and 443?, Can I change that?.
|
||||
|
||||
No, it needs to run on those ports for DNS resolve to work. Ideas or suggestions about how to improve this
|
||||
are welcome
|
||||
|
6
api.go
6
api.go
@ -61,8 +61,8 @@ func main() {
|
||||
}
|
||||
|
||||
// Specific routes
|
||||
r.Host(`{host:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-{port:[0-9]*}.{tld:.*}`).HandlerFunc(proxyMultiplexer)
|
||||
r.Host(`{host:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}.{tld:.*}`).HandlerFunc(proxyMultiplexer)
|
||||
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-{port:[0-9]*}.{tld:.*}`).HandlerFunc(proxyMultiplexer)
|
||||
r.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}.{tld:.*}`).HandlerFunc(proxyMultiplexer)
|
||||
r.HandleFunc("/ping", handlers.Ping).Methods("GET")
|
||||
r.HandleFunc("/sessions/{sessionId}", handlers.GetSession).Methods("GET")
|
||||
r.Handle("/sessions/{sessionId}/instances", http.HandlerFunc(handlers.NewInstance)).Methods("POST")
|
||||
@ -110,7 +110,7 @@ func main() {
|
||||
|
||||
ssl := mux.NewRouter()
|
||||
sslProxyHandler := handlers.NewSSLDaemonHandler()
|
||||
ssl.Host(`{host:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-2375.{tld:.*}`).Handler(sslProxyHandler)
|
||||
ssl.Host(`{subdomain:.*}{node:pwd[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}_[0-9]{1,3}}-2375.{tld:.*}`).Handler(sslProxyHandler)
|
||||
log.Println("Listening TLS on port " + config.SSLPortNumber)
|
||||
|
||||
s := &http.Server{Addr: "0.0.0.0:" + config.SSLPortNumber, Handler: ssl}
|
||||
|
@ -13,10 +13,9 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func getTargetInfo(vars map[string]string, req *http.Request) (string, string, string) {
|
||||
func getTargetInfo(vars map[string]string, req *http.Request) (string, string) {
|
||||
node := vars["node"]
|
||||
port := vars["port"]
|
||||
host := vars["host"]
|
||||
hostPort := strings.Split(req.Host, ":")
|
||||
|
||||
// give priority to the URL host port
|
||||
@ -37,14 +36,7 @@ func getTargetInfo(vars map[string]string, req *http.Request) (string, string, s
|
||||
}
|
||||
}
|
||||
|
||||
if len(host) > 0 {
|
||||
// Remove last "." from host
|
||||
host = strings.TrimSuffix(host, ".")
|
||||
} else {
|
||||
host = req.Host
|
||||
}
|
||||
|
||||
return node, port, host
|
||||
return node, port
|
||||
|
||||
}
|
||||
|
||||
@ -64,7 +56,7 @@ func NewMultipleHostReverseProxy() *httputil.ReverseProxy {
|
||||
}
|
||||
director := func(req *http.Request) {
|
||||
v := mux.Vars(req)
|
||||
node, port, host := getTargetInfo(v, req)
|
||||
node, port := getTargetInfo(v, req)
|
||||
|
||||
if port == "443" {
|
||||
// Only proxy http for now
|
||||
@ -74,7 +66,6 @@ func NewMultipleHostReverseProxy() *httputil.ReverseProxy {
|
||||
req.URL.Scheme = "http"
|
||||
}
|
||||
|
||||
req.Host = host
|
||||
req.URL.Host = fmt.Sprintf("%s:%s", node, port)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ func NewMultipleHostWebsocketReverseProxy() *wsutil.ReverseProxy {
|
||||
director := func(req *http.Request) {
|
||||
v := mux.Vars(req)
|
||||
|
||||
node, port, host := getTargetInfo(v, req)
|
||||
node, port := getTargetInfo(v, req)
|
||||
|
||||
if port == "443" {
|
||||
// Only proxy http for now
|
||||
@ -25,7 +25,6 @@ func NewMultipleHostWebsocketReverseProxy() *wsutil.ReverseProxy {
|
||||
// Only proxy http for now
|
||||
req.URL.Scheme = "ws"
|
||||
}
|
||||
req.Host = host
|
||||
req.URL.Host = fmt.Sprintf("%s:%s", node, port)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user