Skip to content

Commit

Permalink
cors support.
Browse files Browse the repository at this point in the history
closes #40
  • Loading branch information
fiatjaf committed Oct 23, 2022
1 parent 75275d2 commit e37ee82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e37ee82

Please sign in to comment.