Compare commits

..

2 Commits

Author SHA1 Message Date
a4416164cd
Add Access-Control-Allow-Origin and friends
All checks were successful
the build was successful
2018-08-26 18:50:11 +02:00
67c27a6139
Remove cloud profiler 2018-08-26 18:50:00 +02:00
2 changed files with 9 additions and 12 deletions

View File

@ -26,7 +26,6 @@ import (
"regexp"
"time"
"cloud.google.com/go/profiler"
"github.com/gomodule/redigo/redis"
"p83.nl/go/ekster/pkg/microsub"
@ -60,17 +59,6 @@ func newPool(addr string) *redis.Pool {
}
func main() {
if os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") != "" {
if err := profiler.Start(profiler.Config{
Service: "microsub-server",
ServiceVersion: "1.0",
ProjectID: "microsub-server", // optional on GCP
}); err != nil {
log.Fatalf("Cannot start the profiler: %v", err)
}
}
log.Println("eksterd - microsub server")
flag.Parse()

View File

@ -63,6 +63,13 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
if r.Method == http.MethodOptions {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Methods", "GET, POST")
w.Header().Add("Access-Control-Allow-Headers", "Authorization")
return
}
if r.Method == http.MethodGet {
values := r.URL.Query()
action := values.Get("action")
@ -74,6 +81,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Origin", "*")
err = jw.Encode(map[string][]microsub.Channel{
"channels": channels,
})
@ -89,6 +97,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Origin", "*")
jw.SetIndent("", " ")
jw.SetEscapeHTML(false)
err = jw.Encode(timeline)