Configure CORS

This commit is contained in:
Ray Miller 2023-10-08 16:39:55 +01:00
parent ee824da6e0
commit f6920046a8
2 changed files with 8 additions and 1 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.zip

View file

@ -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)