return the http.Server instance to allow manual shutdowns
This commit is contained in:
parent
64d7ab22f3
commit
6179864828
|
@ -36,17 +36,15 @@ type ServeConfig struct {
|
||||||
AllowedOrigins []string
|
AllowedOrigins []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo return the server instance to allow manual shutdowns
|
|
||||||
//
|
|
||||||
// Serve starts a new app web server.
|
// 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 {
|
if len(config.AllowedOrigins) == 0 {
|
||||||
config.AllowedOrigins = []string{"*"}
|
config.AllowedOrigins = []string{"*"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that the latest migrations are applied before starting the server
|
// ensure that the latest migrations are applied before starting the server
|
||||||
if err := runMigrations(app); err != nil {
|
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
|
// 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)
|
router, err := InitApi(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure cors
|
// configure cors
|
||||||
|
@ -104,7 +102,7 @@ func Serve(app core.App, config ServeConfig) error {
|
||||||
CertManager: certManager,
|
CertManager: certManager,
|
||||||
}
|
}
|
||||||
if err := app.OnBeforeServe().Trigger(serveEvent); err != nil {
|
if err := app.OnBeforeServe().Trigger(serveEvent); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ShowStartBanner {
|
if config.ShowStartBanner {
|
||||||
|
@ -143,11 +141,11 @@ func Serve(app core.App, config ServeConfig) error {
|
||||||
go http.ListenAndServe(config.HttpAddr, certManager.HTTPHandler(nil))
|
go http.ListenAndServe(config.HttpAddr, certManager.HTTPHandler(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
return server.ListenAndServeTLS("", "")
|
return server, server.ListenAndServeTLS("", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OR start HTTP server
|
// OR start HTTP server
|
||||||
return server.ListenAndServe()
|
return server, server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
type migrationsConnection struct {
|
type migrationsConnection struct {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func NewServeCommand(app core.App, showStartBanner bool) *cobra.Command {
|
||||||
Use: "serve",
|
Use: "serve",
|
||||||
Short: "Starts the web server (default to 127.0.0.1:8090)",
|
Short: "Starts the web server (default to 127.0.0.1:8090)",
|
||||||
Run: func(command *cobra.Command, args []string) {
|
Run: func(command *cobra.Command, args []string) {
|
||||||
err := apis.Serve(app, apis.ServeConfig{
|
_, err := apis.Serve(app, apis.ServeConfig{
|
||||||
HttpAddr: httpAddr,
|
HttpAddr: httpAddr,
|
||||||
HttpsAddr: httpsAddr,
|
HttpsAddr: httpsAddr,
|
||||||
ShowStartBanner: showStartBanner,
|
ShowStartBanner: showStartBanner,
|
||||||
|
|
Loading…
Reference in New Issue