1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-10-04 17:33:21 +08:00

Update proxy to handle port redirects (#92)

This commit is contained in:
Marcos Nils
2017-02-12 02:25:25 +02:00
committed by GitHub
parent 3dc1f3e601
commit 640d64c3aa
4 changed files with 29 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ import (
"strings"
"time"
"github.com/franela/play-with-docker/config"
"github.com/gorilla/mux"
)
@@ -30,9 +31,15 @@ func NewMultipleHostReverseProxy() *httputil.ReverseProxy {
v := mux.Vars(req)
node := v["node"]
port := v["port"]
if port == "" {
hostPort := strings.Split(req.Host, ":")
// give priority to the URL host port
if len(hostPort) > 1 && hostPort[1] != config.PortNumber {
port = hostPort[1]
} else if port == "" {
port = "80"
}
if strings.HasPrefix(node, "ip") {
// Node is actually an ip, need to convert underscores by dots.
ip := strings.Replace(strings.TrimPrefix(node, "ip"), "_", ".", -1)