diff --git a/main.go b/main.go index 2566d82..604d523 100644 --- a/main.go +++ b/main.go @@ -46,16 +46,14 @@ func main() { func setupRoutes() *http.ServeMux { mux := http.NewServeMux() - mux.HandleFunc("/", utils.WithCORS(ListenAndServe)) - mux.Handle("/static/", utils.WithCORSHandler(http.StripPrefix("/static/", http.FileServer(http.Dir("app/static"))))) - mux.HandleFunc("/favicon.ico", utils.WithCORS(func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/", ListenAndServe) + mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("app/static")))) + mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "app/static/img/favicon.ico") - })) + }) return mux } - - func startServer(config *configTypes.ServerConfig, mux *http.ServeMux) { server := &http.Server{ Addr: config.Server.Port, diff --git a/server/utils/cors.go b/server/utils/cors.go deleted file mode 100644 index ce885d5..0000000 --- a/server/utils/cors.go +++ /dev/null @@ -1,33 +0,0 @@ -package utils - -import "net/http" - -func WithCORS(h http.HandlerFunc) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") - w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST, OPTIONS") - - if r.Method == http.MethodOptions { - w.WriteHeader(http.StatusOK) - return - } - - h(w, r) - } -} - -func WithCORSHandler(h http.Handler) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type") - w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, DELETE, POST, OPTIONS") - - if r.Method == http.MethodOptions { - w.WriteHeader(http.StatusOK) - return - } - - h.ServeHTTP(w, r) - } -} \ No newline at end of file