Created
August 15, 2019 19:52
-
-
Save jkutner/2f4616e16158ff317e9843c1ed889df7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"net/http/httputil" | |
_ "net/http/pprof" | |
"os" | |
"strings" | |
log "github.com/sirupsen/logrus" | |
defaultLog "log" | |
) | |
func init() { | |
// Setting default level to debug | |
log.SetLevel(log.DebugLevel) | |
} | |
func main() { | |
logger := log.New() | |
w := logger.Writer() | |
defaultLog.SetOutput(logger.Writer()) | |
defer w.Close() | |
log.WithFields(log.Fields{ | |
"Function": "main", | |
}).Fatal("The application has exited. Check you have the required ENV's.\n", http.ListenAndServe(":"+os.Getenv("PORT"), | |
&httputil.ReverseProxy{ | |
Director: func(r *http.Request) { | |
r.URL.Scheme = "https" | |
r.URL.Path = "/v2/jkutner/pack/manifests/latest" | |
r.URL.Host = "registry.hub.docker.com" | |
r.Host = "registry.hub.docker.com" | |
}, | |
ErrorLog: defaultLog.New(w, "", 0), | |
ModifyResponse: func(resp *http.Response) (err error) { | |
resp.Header.Set("Location", strings.Replace(resp.Header.Get("Location"), "registry.hub.docker.com", os.Getenv("HEROKU_APP_NAME")+".herokuapp.com", 1)) | |
return | |
}, | |
}, | |
)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment