diff --git a/main.go b/main.go index b14c7b0..91210dd 100644 --- a/main.go +++ b/main.go @@ -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") @@ -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) } diff --git a/pkg/gofaas/template/main.go b/pkg/gofaas/template/main.go index 55bfdba..f59ed9e 100644 --- a/pkg/gofaas/template/main.go +++ b/pkg/gofaas/template/main.go @@ -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) }