Skip to content

Instantly share code, notes, and snippets.

@derrickwilliams
Created November 6, 2017 21:39
Show Gist options
  • Select an option

  • Save derrickwilliams/2a76b700e5de6145b7ec8b0e14b12266 to your computer and use it in GitHub Desktop.

Select an option

Save derrickwilliams/2a76b700e5de6145b7ec8b0e14b12266 to your computer and use it in GitHub Desktop.
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