#109 begin migration

This commit is contained in:
Tim
2024-08-21 23:33:06 +02:00
parent 69b8efc8b9
commit 38f2282049
31 changed files with 68 additions and 5814 deletions

28
middleware/cors.go Normal file
View File

@@ -0,0 +1,28 @@
package middleware
import (
"log"
"net/http"
"os"
)
func EnableCors(next http.Handler) http.Handler {
var frontent_url = os.Getenv("FRONTEND_URL")
if frontent_url == "" {
log.Fatal("FRONTEND_URL is not set")
}
log.Println("FRONTEND_URL is", frontent_url)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", frontent_url)
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}