Created
November 6, 2017 21:39
-
-
Save derrickwilliams/2a76b700e5de6145b7ec8b0e14b12266 to your computer and use it in GitHub Desktop.
Revisions
-
derrickwilliams created this gist
Nov 6, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ package main import ( "fmt" "log" "net/http" "net/http/httputil" "net/url" "github.com/darkhelmet/env" ) var ( port = env.IntDefault("PORT", 5000) ) func main() { proxyUrl, err := url.Parse(env.String("PROXY_URL")) if err != nil { log.Fatalf("failed parsing url: %s", err) } proxy := &httputil.ReverseProxy{ Director: func(req *http.Request) { req.URL.Scheme = proxyUrl.Scheme req.URL.Host = proxyUrl.Host req.URL.Path = req.URL.Path req.Host = proxyUrl.Host }, } log.Printf("listening on port %d", port) http.ListenAndServe(fmt.Sprintf(":%d", port), proxy) }