Skip to content

Commit d3c7d38

Browse files
committed
add CreateServerWithMux function
Signed-off-by: Grant Linville <[email protected]>
1 parent a75da42 commit d3c7d38

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/daemon/daemon.go

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ func CreateServer() (*http.Server, error) {
2525
return server, nil
2626
}
2727

28+
// CreateServerWithMux creates a new HTTP server with TLS configured for GPTScript.
29+
// This function should be used when creating a new server for a daemon tool with a custom ServeMux.
30+
// The server should then be started with the StartServer function.
31+
func CreateServerWithMux(mux *http.ServeMux) (*http.Server, error) {
32+
tlsConfig, err := getTLSConfig()
33+
if err != nil {
34+
return nil, fmt.Errorf("failed to get TLS config: %v", err)
35+
}
36+
37+
server := &http.Server{
38+
Addr: fmt.Sprintf("127.0.0.1:%s", os.Getenv("PORT")),
39+
TLSConfig: tlsConfig,
40+
Handler: mux,
41+
}
42+
return server, nil
43+
}
44+
2845
// StartServer starts an HTTP server created by the CreateServer function.
2946
// This is for use with daemon tools.
3047
func StartServer(server *http.Server) error {

0 commit comments

Comments
 (0)