@@ -20,6 +20,7 @@ import (
20
20
"github.com/acorn-io/gptscript/pkg/runner"
21
21
"github.com/acorn-io/gptscript/pkg/types"
22
22
"github.com/olahol/melody"
23
+ "github.com/rs/cors"
23
24
)
24
25
25
26
type Options struct {
@@ -37,7 +38,7 @@ func complete(opts []Options) (runnerOpts []runner.Options, result Options) {
37
38
})
38
39
}
39
40
if result .ListenAddress == "" {
40
- result .ListenAddress = "127.0.0.1:89090 "
41
+ result .ListenAddress = "127.0.0.1:9090 "
41
42
}
42
43
return
43
44
}
@@ -149,6 +150,7 @@ func (s *Server) run(rw http.ResponseWriter, req *http.Request) {
149
150
go func () {
150
151
_ , _ = s .runner .Run (ctx , prg , os .Environ (), string (body ))
151
152
}()
153
+ rw .Header ().Set ("Content-Type" , "application/json" )
152
154
err := json .NewEncoder (rw ).Encode (map [string ]any {
153
155
"id" : id ,
154
156
})
@@ -169,12 +171,14 @@ func (s *Server) Start(ctx context.Context) error {
169
171
s .melody .HandleConnect (s .Connect )
170
172
go s .events .Start (ctx )
171
173
log .Infof ("Listening on http://%s" , s .listenAddress )
172
- server := & http.Server {Addr : s .listenAddress , Handler : s }
174
+ handler := cors .Default ().Handler (s )
175
+ server := & http.Server {Addr : s .listenAddress , Handler : handler }
173
176
context .AfterFunc (ctx , func () {
174
177
ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
175
178
defer cancel ()
176
179
_ = server .Shutdown (ctx )
177
180
})
181
+
178
182
return server .ListenAndServe ()
179
183
}
180
184
0 commit comments