main.go 580 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "net/http/httputil"
  7. "net/url"
  8. "os"
  9. "time"
  10. )
  11. func main() {
  12. origin := os.Getenv("ORIGIN_SERVER")
  13. if origin == "" {
  14. origin = "http://localhost:9090/"
  15. }
  16. sleep := time.Minute
  17. originURL, _ := url.Parse(origin)
  18. proxy := httputil.NewSingleHostReverseProxy(originURL)
  19. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  20. fmt.Printf("sleeping for %s then proxying request: %s", sleep.String(), r.RequestURI)
  21. <-time.After(sleep)
  22. proxy.ServeHTTP(w, r)
  23. })
  24. log.Fatal(http.ListenAndServe(":3011", nil))
  25. }