diff --git a/api/server/auth/auth.go b/api/server/auth/auth.go index 13b3c999..f0e38562 100644 --- a/api/server/auth/auth.go +++ b/api/server/auth/auth.go @@ -1,6 +1,7 @@ package auth import ( + "context" "fmt" "net" "net/http" @@ -84,8 +85,14 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { // a file not served by the resolver has been requested (e.g. favicon.ico) endpoint = &resolver.Endpoint{Path: req.URL.Path} } else if err != nil { + logger.Error(err) w.WriteHeader(http.StatusInternalServerError) return + } else if err == nil { + // set the endpoint in the context so it can be used to resolve + // the request later + ctx := context.WithValue(req.Context(), resolver.Endpoint{}, endpoint) + *req = *req.WithContext(ctx) } // construct the resource name, e.g. home => go.micro.web.home @@ -132,6 +139,9 @@ func (h authHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } func namespaceFromRequest(req *http.Request) (string, error) { + // needed to tmp debug host in prod. will be removed. + logger.Infof("Host is '%v'; URL Host is '%v'; URL Hostname is '%v'", req.Host, req.URL.Host, req.URL.Hostname()) + // determine the host, e.g. dev.micro.mu:8080 host := req.URL.Hostname() if len(host) == 0 { @@ -139,8 +149,6 @@ func namespaceFromRequest(req *http.Request) (string, error) { host, _, _ = net.SplitHostPort(req.Host) } - logger.Infof("Host is %v", host) - // check for an ip address if net.ParseIP(host) != nil { return auth.DefaultNamespace, nil