parent
3d2cb71808
commit
a45aaf14c3
13
src/main.go
13
src/main.go
|
|
@ -3,16 +3,23 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
if port == "" {
|
||||||
|
port = "80"
|
||||||
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
targetURL := "https://" + r.Host + r.RequestURI
|
targetURL := "https://" + r.Host + r.RequestURI
|
||||||
|
log.Printf("[REDIRECT] %s - %s (%s)", targetURL, r.RemoteAddr, r.UserAgent())
|
||||||
http.Redirect(w, r, targetURL, http.StatusMovedPermanently)
|
http.Redirect(w, r, targetURL, http.StatusMovedPermanently)
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Println("Service running on :80")
|
log.Printf("[INFO] Service running on :%s", port)
|
||||||
if err := http.ListenAndServe(":80", nil); err != nil {
|
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||||
log.Fatalf("%v", err)
|
log.Fatalf("[ERROR] %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue