diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fa1385d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/.gitignore b/.gitignore index 6f72f89..c3a5712 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ go.work.sum # env file .env + +build/* diff --git a/src/go.mod b/src/go.mod new file mode 100644 index 0000000..e990ff1 --- /dev/null +++ b/src/go.mod @@ -0,0 +1,3 @@ +module itsmrval/http-to-https + +go 1.22.5 diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..4d9ea8b --- /dev/null +++ b/src/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + targetURL := "https://" + r.Host + r.RequestURI + http.Redirect(w, r, targetURL, http.StatusMovedPermanently) + }) + + log.Println("Service running on :80") + if err := http.ListenAndServe(":80", nil); err != nil { + log.Fatalf("%v", err) + } +}