diff --git a/apis/serve.go b/apis/serve.go index 802a676a..f423785e 100644 --- a/apis/serve.go +++ b/apis/serve.go @@ -36,17 +36,15 @@ type ServeConfig struct { AllowedOrigins []string } -// @todo return the server instance to allow manual shutdowns -// // Serve starts a new app web server. -func Serve(app core.App, config ServeConfig) error { +func Serve(app core.App, config ServeConfig) (*http.Server, error) { if len(config.AllowedOrigins) == 0 { config.AllowedOrigins = []string{"*"} } // ensure that the latest migrations are applied before starting the server if err := runMigrations(app); err != nil { - return err + return nil, err } // reload app settings in case a new default value was set with a migration @@ -60,7 +58,7 @@ func Serve(app core.App, config ServeConfig) error { router, err := InitApi(app) if err != nil { - return err + return nil, err } // configure cors @@ -104,7 +102,7 @@ func Serve(app core.App, config ServeConfig) error { CertManager: certManager, } if err := app.OnBeforeServe().Trigger(serveEvent); err != nil { - return err + return nil, err } if config.ShowStartBanner { @@ -143,11 +141,11 @@ func Serve(app core.App, config ServeConfig) error { go http.ListenAndServe(config.HttpAddr, certManager.HTTPHandler(nil)) } - return server.ListenAndServeTLS("", "") + return server, server.ListenAndServeTLS("", "") } // OR start HTTP server - return server.ListenAndServe() + return server, server.ListenAndServe() } type migrationsConnection struct { diff --git a/cmd/serve.go b/cmd/serve.go index b6ffc3e1..2b900af9 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -20,7 +20,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command { Use: "serve", Short: "Starts the web server (default to 127.0.0.1:8090)", Run: func(command *cobra.Command, args []string) { - err := apis.Serve(app, apis.ServeConfig{ + _, err := apis.Serve(app, apis.ServeConfig{ HttpAddr: httpAddr, HttpsAddr: httpsAddr, ShowStartBanner: showStartBanner,