summaryrefslogtreecommitdiff
path: root/backend/main.go
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-11-27 22:45:26 -0500
committerTucker Evans <tuckerevans24@gmail.com>2019-11-27 22:45:26 -0500
commitb402ebba4f9c93a0040972748d66f9c4c6b02eb7 (patch)
treed7ae5d7f2beef74332697c7d8b4d9e36a8fee28b /backend/main.go
parent0f7b0118c5a8290ed4d230a8e4bfc96daafea116 (diff)
Add CORS headers to backend responsesbackend-v2.0
Access-Control-Allow-Origin:* header added to API responses to allow angular to access API. Note: This allows all domains to access this API through browser javascript See <https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS> for a description of CORS
Diffstat (limited to 'backend/main.go')
-rw-r--r--backend/main.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/backend/main.go b/backend/main.go
index 4766de2..0a95fc8 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -31,6 +31,8 @@ func MakeAPIResponse(status int, msg string, data interface{}) *APIResponse {
}
func RecipeList(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*") //Enable CORS
+
if r.Method == "GET" {
var ids []int
var id int
@@ -137,6 +139,8 @@ func RecipeList(w http.ResponseWriter, r *http.Request) {
}
func SingleRecipe(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Access-Control-Allow-Origin", "*") //Enable CORS
+
recipe_id, err := strconv.Atoi(r.URL.Path[len("/recipes/"):])
if err != nil {
fmt.Println("Not a valid ID")