summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-12-07 14:27:26 -0500
committerGitHub <noreply@github.com>2019-12-07 14:27:26 -0500
commit5cf3689290666f70cd631d7b3d40a2ed245a3fce (patch)
treee6f2938377890774ff3e80fae8f77797917a46e5 /backend
parentcafe1b4fd3cc02554f44ffbaa8467d867a6838cb (diff)
parent658dea27e47e3aab24598a74ee9940f82bea2368 (diff)
Merge pull request #12 from tuckerevans/REST-service
Backend REST Service implementation
Diffstat (limited to 'backend')
-rw-r--r--backend/main.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go
index 0bd5ebf..001a5cb 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -93,6 +93,11 @@ func RecipeList(w http.ResponseWriter, r *http.Request) {
sendResponse(w, http.StatusCreated, "Recipe added successfully",
recipe)
+ } else if r.Method == "OPTIONS" {
+
+ w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS") //Enable CORS
+ w.Header().Set("Access-Control-Allow-Headers", "Content-Type") //Enable CORS
+ sendResponse(w, http.StatusOK, "Set Allowed Methods CORS", nil)
} else {
sendResponse(w, http.StatusMethodNotAllowed, "Invalid method",
nil)
@@ -183,6 +188,11 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) {
"Recipe Deleted Successfully", nil)
}
+ } else if r.Method == "OPTIONS" {
+
+ w.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS") //Enable CORS
+ w.Header().Set("Access-Control-Allow-Headers", "Content-Type") //Enable CORS
+ sendResponse(w, http.StatusOK, "Set Allowed Methods CORS", nil)
} else {
sendResponse(w, http.StatusMethodNotAllowed, "Invalid method",
nil)