Skip to content

Commit

Permalink
use json only when multiple outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Mar 11, 2020
1 parent 6cf7090 commit 3902c23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func main() {
}
} else {
body = res.Data().([]byte)
go func() {
cache.Add(urlPath, 30*time.Minute, body)
}()
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Max-Age", "86400")
Expand All @@ -78,9 +81,6 @@ func main() {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
w.Write(body)
go func() {
cache.Add(urlPath, 30*time.Minute, body)
}()
})
http.ListenAndServe(":"+port, nil)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/gofaas/template/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Max")
w.Header().Set("Access-Control-Allow-Credentials", "true")
}
{{ if eq 1 (len .OutputParams) }}
w.Header().Set("Content-Type", "text/plain")
{{else}}
w.Header().Set("Content-Type", "text/javascript")
{{end}}
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
w.Write(response)
}
Expand Down

0 comments on commit 3902c23

Please sign in to comment.