diff --git a/main.go b/main.go index 7866be8..cfb8a68 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,12 @@ func main() { router := router.New() + router.Handle("OPTIONS /", func(w http.ResponseWriter, r *http.Request) error { + w.WriteHeader(200) + fmt.Fprintf(w, "ok") + return nil + }) + router.Handle("POST /auth/register", func(w http.ResponseWriter, r *http.Request) error { var body struct { Email string `json:"email"` diff --git a/router/router.go b/router/router.go index f07b90e..1d9435e 100644 --- a/router/router.go +++ b/router/router.go @@ -32,6 +32,11 @@ func (router *router) SendJSON(w http.ResponseWriter, data any) error { func (router *router) Handle(pattern string, handler func(w http.ResponseWriter, r *http.Request) error) { router.mux.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Credentials", "true") + w.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000") + w.Header().Set("Access-Control-Allow-Methods", "GET,POST,PATCH,DELETE,OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Content-Length") + if err := handler(w, r); err != nil { router.SendJSON(w, struct { Error string `json:"error"`