diff --git a/pkg/cmds/serve.go b/pkg/cmds/serve.go index 5dd6afe..af16082 100644 --- a/pkg/cmds/serve.go +++ b/pkg/cmds/serve.go @@ -3,6 +3,7 @@ package cmds import ( "fmt" "net/http" + "sync" "git.itzana.me/strafesnet/go-grpc/auth" "git.itzana.me/strafesnet/maps-service/pkg/api" @@ -138,7 +139,30 @@ func serve(ctx *cli.Context) error { log.WithError(err).Fatal("failed to initialize api server") } - // idk how else to do this - go http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2) - return http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv) + var wg sync.WaitGroup + wg.Add(2) // We'll wait for two goroutines, one for each server. + + // First server + go func() { + defer wg.Done() + err := http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2) + if err != nil { + log.Printf("Internal server error: %v", err) + } + }() + + // Second server + go func() { + defer wg.Done() + err := http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv) + if err != nil { + log.Printf("External server error: %v", err) + } + }() + + // Wait for both servers to finish. + wg.Wait() + log.Println("Both servers have stopped.") + + return nil }