1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
diff --git a/go.work.sum b/go.work.sum
index 6a07974a247b630caeecc0cf831e04c2cb82da32..e2446a065d43ab64119e938e20b356cb3150803d 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -1 +1,24 @@
+cloud.google.com/go/compute v1.19.1/go.mod h1:6ylj3a05WF8leseCdIf77NK0g1ey+nj5IKd5/kvShxE=
+cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
+github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
+github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
+github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
+github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
+github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
+github.com/envoyproxy/go-control-plane v0.11.1-0.20230524094728-9239064ad72f/go.mod h1:sfYdkwUW4BA3PbKjySwjJy+O4Pu0h62rlqCMHNk+K+Q=
+github.com/envoyproxy/protoc-gen-validate v0.10.1/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss=
+github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
+github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
+github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
+golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
+golang.org/x/oauth2 v0.7.0/go.mod h1:hPLQkd9LyjfXTiRohC/41GhcFqxisoUQ99sCUOHO9x4=
+golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
+google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 h1:9NWlQfY2ePejTmfwUH1OWwmznFa+0kKcHGPDvcPza9M=
+google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54/go.mod h1:zqTuNwFlFRsw5zIts5VnzLQxSRqh+CGOTVMlYbY0Eyk=
+google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
diff --git a/internal/client/apidocs.go b/internal/client/apidocs.go
index 4f3185cc9917e3bcb1c5f7dd302eda3d74eaaab2..b1754711fcd31f9142d1114887230c9c61687650 100644
--- a/internal/client/apidocs.go
+++ b/internal/client/apidocs.go
@@ -5,16 +5,26 @@ // SPDX-License-Identifier: AGPL-3.0-or-later
import (
_ "embed"
+ "fmt"
"net/http"
+ "net/url"
)
type apiDocWrapper struct {
- next http.Handler
+ next http.Handler
+ remoteHost string
+ secure string
}
-func NewDocWrapper(next http.Handler) *apiDocWrapper {
+func NewDocWrapper(next http.Handler, connectTo *url.URL) *apiDocWrapper {
+ secure := "s"
+ if connectTo.Query().Has("insecure") {
+ secure = ""
+ }
return &apiDocWrapper{
- next: next,
+ next: next,
+ remoteHost: connectTo.Host,
+ secure: secure,
}
}
@@ -24,6 +34,8 @@ w.Header().Add("Content-Type", "text/html")
w.Write(docPage)
return
}
+ w.Header().Add("Access-Control-Allow-Origin", fmt.Sprintf("http%s://%s", a.secure, a.remoteHost))
+ w.Header().Add("Access-Control-Allow-Methods", "*")
a.next.ServeHTTP(w, r)
}
diff --git a/internal/client/client.go b/internal/client/client.go
index c7004bcfe77a7a868370a5a1a9a622c76a7e6b97..4e48868dc26e3c8e9cb0fea7909f96683923f565 100644
--- a/internal/client/client.go
+++ b/internal/client/client.go
@@ -46,7 +46,7 @@ }
defer p.Close()
status := api.StatusConnectionConnecting
- go StartRestServer(context.Background(), p, &status)
+ go StartRestServer(context.Background(), p, &status, u)
glog.Debugf("loading file %q…", u.Query().Get("file"))
err = p.LoadFile(u.Query().Get("file"))
diff --git a/internal/client/restapi.go b/internal/client/restapi.go
index 61cb9ec24eaaf93302a45da3bc13a022fac3bd37..0871adacc149612f377f409e601b1321cd37908d 100644
--- a/internal/client/restapi.go
+++ b/internal/client/restapi.go
@@ -7,6 +7,7 @@ import (
"context"
"fmt"
"net/http"
+ "net/url"
"os"
"path"
"regexp"
@@ -24,7 +25,7 @@ "git.sr.ht/~poldi1405/glog"
"github.com/ogen-go/ogen/ogenerrors"
)
-func StartRestServer(_ context.Context, p player.Interface, status *api.StatusConnection) error {
+func StartRestServer(_ context.Context, p player.Interface, status *api.StatusConnection, remote *url.URL) error {
r := &restServer{p, status}
srv, err := api.NewServer(r, api.WithErrorHandler(ogenerrors.DefaultErrorHandler))
@@ -32,7 +33,7 @@ if err != nil {
return fmt.Errorf("failed to create client API: %w", err)
}
- wrapper := NewDocWrapper(srv)
+ wrapper := NewDocWrapper(srv, remote)
httpSrv := &http.Server{
Addr: "[::1]:21558",
|