fix: add baseURL to endpoints

This commit is contained in:
Jon Lundy 2022-08-14 13:56:55 -06:00
parent 01285ebc9a
commit 2af4652f73
Signed by untrusted user who does not match committer: xuu
GPG Key ID: C63E6D61F3035024
4 changed files with 45 additions and 5 deletions

37
.air.toml Normal file
View File

@ -0,0 +1,37 @@
root = "."
testdata_dir = "data"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ data/
!*.secret
local.mk
logzio.yml
tmp/

View File

@ -60,7 +60,7 @@ func run(ctx context.Context) error {
return err
}
svc, err := msgbus.New(ctx, es)
svc, err := msgbus.New(ctx, es, env("EV_BASE_URL", "https://ev.sour.is/inbox/"))
if err != nil {
return err
}

View File

@ -8,6 +8,7 @@ import (
"fmt"
"io"
"net/http"
"path"
"strconv"
"strings"
"time"
@ -20,17 +21,18 @@ import (
)
type service struct {
baseURL string
es *es.EventStore
}
func New(ctx context.Context, es *es.EventStore) (*service, error) {
func New(ctx context.Context, es *es.EventStore, baseURL string) (*service, error) {
ctx, span := logz.Span(ctx)
defer span.End()
if err := event.Register(ctx, &PostEvent{}); err != nil {
return nil, err
}
return &service{es}, nil
return &service{baseURL, es}, nil
}
var upgrader = websocket.Upgrader{
@ -143,7 +145,7 @@ func (s *service) getUser(w http.ResponseWriter, r *http.Request) {
Endpoint string `json:"endpoint"`
Key string `json:"key"`
}{
Endpoint: a.Inbox.String(),
Endpoint: path.Join(s.baseURL, a.Inbox.String()),
Key: a.Pubkey.ID().String(),
})
if err != nil {