From 2a75d70b77d9b61f35dc0f7d59ea9fcbe66638b3 Mon Sep 17 00:00:00 2001 From: shirou Date: Wed, 30 Jan 2019 19:11:58 +0900 Subject: [PATCH] add CORS headers to OPTIONS method. --- apisprout.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apisprout.go b/apisprout.go index aad217b..dfd6272 100644 --- a/apisprout.go +++ b/apisprout.go @@ -381,6 +381,9 @@ func server(cmd *cobra.Command, args []string) { if !viper.GetBool("disable-cors") { // Handle pre-flight OPTIONS request if (*req).Method == "OPTIONS" { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") + w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization") return } }