From f6920046a8833464b3774aea78829765f821a709 Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Sun, 8 Oct 2023 16:39:55 +0100 Subject: [PATCH] Configure CORS --- .gitignore | 1 + cloudfn.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4c4ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/cloudfn.go b/cloudfn.go index 75534f1..489ebc5 100644 --- a/cloudfn.go +++ b/cloudfn.go @@ -52,7 +52,13 @@ func init() { if err := initializeDB(ctx, bucketName, objectName); err != nil { panic(err) } - var corsHandler = cors.Default() + corsHandler := cors.New(cors.Options{ + AllowedOrigins: []string{"*"}, + AllowedHeaders: []string{"*"}, + AllowedMethods: []string{http.MethodPost}, + AllowCredentials: false, + MaxAge: 3600, + }) log.Println("Registering HTTP function with the Functions Framework") functions.HTTP("WordSearch", func(w http.ResponseWriter, r *http.Request) { corsHandler.ServeHTTP(w, r, handleFormSubmission)