Created
November 6, 2017 21:39
-
-
Save derrickwilliams/2a76b700e5de6145b7ec8b0e14b12266 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 ( | |
| "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) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment