Skip to content

Commit 199a582

Browse files
committed
CORS support
1 parent 727668c commit 199a582

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ require (
4242
github.com/onsi/gomega v1.29.0 // indirect
4343
github.com/pmezard/go-difflib v1.0.0 // indirect
4444
github.com/rogpeppe/go-internal v1.11.0 // indirect
45+
github.com/rs/cors v1.10.1 // indirect
4546
github.com/samber/lo v1.38.1 // indirect
4647
github.com/samber/slog-logrus v1.0.0 // indirect
4748
github.com/spf13/pflag v1.0.5 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
8787
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
8888
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
8989
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
90+
github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=
91+
github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
9092
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
9193
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
9294
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=

pkg/server/server.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/acorn-io/gptscript/pkg/runner"
2121
"github.com/acorn-io/gptscript/pkg/types"
2222
"github.com/olahol/melody"
23+
"github.com/rs/cors"
2324
)
2425

2526
type Options struct {
@@ -170,12 +171,14 @@ func (s *Server) Start(ctx context.Context) error {
170171
s.melody.HandleConnect(s.Connect)
171172
go s.events.Start(ctx)
172173
log.Infof("Listening on http://%s", s.listenAddress)
173-
server := &http.Server{Addr: s.listenAddress, Handler: s}
174+
handler := cors.Default().Handler(s)
175+
server := &http.Server{Addr: s.listenAddress, Handler: handler}
174176
context.AfterFunc(ctx, func() {
175177
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
176178
defer cancel()
177179
_ = server.Shutdown(ctx)
178180
})
181+
179182
return server.ListenAndServe()
180183
}
181184

0 commit comments

Comments
 (0)