cors support.

closes https://github.com/nbd-wtf/satdress/issues/40
This commit is contained in:
fiatjaf 2022-10-23 09:47:37 -03:00
parent 75275d2fdd
commit e37ee82b9c
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
3 changed files with 10 additions and 5 deletions

1
go.mod
View File

@ -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
)

1
go.sum
View File

@ -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=

13
main.go
View File

@ -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,