diff --git a/README.md b/README.md index 680aa88..ca378d5 100644 --- a/README.md +++ b/README.md @@ -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-.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 diff --git a/api.go b/api.go index e94079a..5fddca4 100644 --- a/api.go +++ b/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} diff --git a/handlers/reverseproxy.go b/handlers/reverseproxy.go index e1ff270..184ed2d 100644 --- a/handlers/reverseproxy.go +++ b/handlers/reverseproxy.go @@ -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) } diff --git a/handlers/websocket_reverseproxy.go b/handlers/websocket_reverseproxy.go index e8bed71..92d87bd 100644 --- a/handlers/websocket_reverseproxy.go +++ b/handlers/websocket_reverseproxy.go @@ -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) }