diff --git a/Makefile b/Makefile index c7912bb..fbb0fee 100644 --- a/Makefile +++ b/Makefile @@ -20,4 +20,9 @@ endif gqlgen load: - watch -n .1 "http POST localhost:8080/event/asdf/test a=b one=1 two:='{\"v\":2}' | jq" \ No newline at end of file + watch -n .1 "http POST localhost:8080/event/asdf/test a=b one=1 two:='{\"v\":2}' | jq" + +bi: + go build . + sudo mv ev /usr/local/bin/ + sudo systemctl restart ev diff --git a/go.mod b/go.mod index 045cc3f..44f1b45 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/mitchellh/mapstructure v1.3.1 // indirect + github.com/rs/cors v1.8.2 // indirect ) require ( diff --git a/go.sum b/go.sum index bb91854..2afb347 100644 --- a/go.sum +++ b/go.sum @@ -37,6 +37,8 @@ github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNs github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= +github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= diff --git a/main.go b/main.go index 28ba878..a162053 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "context" "log" "net/http" @@ -9,8 +10,9 @@ import ( "time" "golang.org/x/sync/errgroup" - "github.com/99designs/gqlgen/graphql/handler" + "github.com/rs/cors" + "github.com/sour-is/ev/api/gql_ev" "github.com/sour-is/ev/internal/graph" "github.com/sour-is/ev/internal/graph/generated" @@ -53,9 +55,23 @@ func run(ctx context.Context) error { s := http.Server{ Addr: env("EV_HTTP", ":8080"), } - http.Handle("/", playground.Handler("GraphQL playground", "/gql")) - http.Handle("/gql", res.ChainMiddlewares(gql)) - http.Handle("/event/", http.StripPrefix("/event/", svc)) + mux := http.NewServeMux() + + mux.Handle("/", playground.Handler("GraphQL playground", "/gql")) + mux.Handle("/gql", res.ChainMiddlewares(gql)) + mux.Handle("/inbox/", http.StripPrefix("/inbox/", svc)) + + wk := http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `{ + "endpoint": "https://ev.sour.is/inbox/01GA4Q3NDX4TPAZ2EZ8E92CQE6", + "key": "kex1pqwqatj6sge7qaqrsvk4u4yhue4x3vej8znetkwj6a5k0xds2fmqqe3plh" +}`) + }, + ) + mux.Handle("/.well-known/salty/0ce550020ce36a9932b286b141edd515d33c2b0f51c715445de89ae106345993.json", wk) + + s.Handler = cors.AllowAll().Handler(mux) log.Print("Listen on ", s.Addr) g, ctx := errgroup.WithContext(ctx) diff --git a/pkg/msgbus/service.go b/pkg/msgbus/service.go index 0bb599d..4a6da6e 100644 --- a/pkg/msgbus/service.go +++ b/pkg/msgbus/service.go @@ -67,7 +67,7 @@ func (s *service) get(w http.ResponseWriter, r *http.Request) { var pos, count int64 = -1, -99 qry := r.URL.Query() - if i, err := strconv.ParseInt(qry.Get("idx"), 10, 64); err == nil { + if i, err := strconv.ParseInt(qry.Get("index"), 10, 64); err == nil { pos = i } if i, err := strconv.ParseInt(qry.Get("n"), 10, 64); err == nil { @@ -177,7 +177,7 @@ func (s *service) websocket(w http.ResponseWriter, r *http.Request) { var pos int64 = -1 qry := r.URL.Query() - if i, err := strconv.ParseInt(qry.Get("idx"), 10, 64); err == nil { + if i, err := strconv.ParseInt(qry.Get("index"), 10, 64); err == nil { pos = i }