gomain.go.boiler 837 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // {{.author}} {{.email}}
  2. package main
  3. import (
  4. "log"
  5. "net/http"
  6. "net/http/httputil"
  7. "net/url"
  8. "os"
  9. "github.com/gohxs/prettylog"
  10. "github.com/gohxs/webu"
  11. )
  12. func main() {
  13. prettylog.Global()
  14. mux := http.NewServeMux()
  15. var assetHandler http.Handler
  16. if os.Getenv("DEBUG") == "1" {
  17. //log.Println("DEBUG MODE: reverse proxy localhost:8081")
  18. proxyURL, err := url.Parse("http://localhost:8080")
  19. if err != nil {
  20. log.Fatal(err)
  21. }
  22. rp := httputil.NewSingleHostReverseProxy(proxyURL)
  23. rp.ErrorLog = prettylog.New("rproxy")
  24. assetHandler = rp
  25. } else {
  26. // Check folder web?
  27. assetHandler = webu.StaticHandler("web", "index.html")
  28. //staticHandler = flowuiassets.AssetHandleFunc
  29. }
  30. // Reverse proxy
  31. //
  32. mux.Handle("/", assetHandler)
  33. log.Println("Listening at port: :2000")
  34. http.ListenAndServe(":2000", mux)
  35. }