diff --git a/go.mod b/go.mod index 917ee7c..797b03f 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/kelseyhightower/envconfig v1.4.0 github.com/lib/pq v1.10.3 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 + github.com/rs/cors v1.7.0 github.com/rs/zerolog v1.23.0 github.com/tidwall/sjson v1.1.7 ) diff --git a/go.sum b/go.sum index a113750..4d67cb6 100644 --- a/go.sum +++ b/go.sum @@ -650,6 +650,7 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= diff --git a/main.go b/main.go index 77c0e5e..f105699 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/gorilla/mux" "github.com/kelseyhightower/envconfig" _ "github.com/lib/pq" + "github.com/rs/cors" "github.com/rs/zerolog" ) @@ -32,10 +33,12 @@ type Settings struct { TorProxyURL string `envconfig:"TOR_PROXY_URL"` } -var s Settings -var db *pebble.DB -var router = mux.NewRouter() -var log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr}) +var ( + s Settings + db *pebble.DB + router = mux.NewRouter() + log = zerolog.New(os.Stderr).Output(zerolog.ConsoleWriter{Out: os.Stderr}) +) //go:embed index.html var indexHTML string @@ -139,7 +142,7 @@ func main() { api.HandleFunc("/users/{name}@{domain}", DeleteUser).Methods("DELETE") srv := &http.Server{ - Handler: router, + Handler: cors.Default().Handler(router), Addr: s.Host + ":" + s.Port, WriteTimeout: 15 * time.Second, ReadTimeout: 15 * time.Second,