// Serve starts the horizon system, binding it to a socket, setting up // the shutdown signals and starting the appropriate db-streaming pumps. func (a *App) Serve() { a.web.router.Compile() http.Handle("/", a.web.router) listenStr := fmt.Sprintf(":%d", a.config.Port) listener := bind.Socket(listenStr) log.Infof(a.ctx, "Starting horizon on %s", listener.Addr()) graceful.HandleSignals() bind.Ready() graceful.PreHook(func() { log.Info(a.ctx, "received signal, gracefully stopping") a.Cancel() }) graceful.PostHook(func() { log.Info(a.ctx, "stopped") }) if a.config.Autopump { sse.SetPump(a.ctx, sse.AutoPump) } else { sse.SetPump(a.ctx, db.NewLedgerClosePump(a.ctx, a.historyDb)) } err := graceful.Serve(listener, http.DefaultServeMux) if err != nil { log.Panic(a.ctx, err) } graceful.Wait() }
// Serve starts the horizon system, binding it to a socket, setting up // the shutdown signals and starting the appropriate db-streaming pumps. func (a *App) Serve() { a.web.router.Compile() http.Handle("/", a.web.router) listenStr := fmt.Sprintf(":%d", a.config.Port) listener := bind.Socket(listenStr) log.Infof("Starting horizon on %s", listener.Addr()) graceful.HandleSignals() bind.Ready() graceful.PreHook(func() { log.Info("received signal, gracefully stopping") a.Close() }) graceful.PostHook(func() { log.Info("stopped") }) sse.SetPump(a.pump.Subscribe()) err := graceful.Serve(listener, http.DefaultServeMux) if err != nil { log.Panic(err) } graceful.Wait() }
// Serve starts the horizon system, binding it to a socket, setting up // the shutdown signals and starting the appropriate db-streaming pumps. func (a *App) Serve() { a.web.router.Compile() http.Handle("/", a.web.router) addr := fmt.Sprintf(":%d", a.config.Port) srv := &graceful.Server{ Timeout: 10 * time.Second, Server: &http.Server{ Addr: addr, Handler: http.DefaultServeMux, }, ShutdownInitiated: func() { log.Info("received signal, gracefully stopping") a.Close() }, } http2.ConfigureServer(srv.Server, nil) sse.SetPump(a.pump.Subscribe()) log.Infof("Starting horizon on %s", addr) var err error if a.config.TLSCert != "" { err = srv.ListenAndServeTLS(a.config.TLSCert, a.config.TLSKey) } else { err = srv.ListenAndServe() } if err != nil { log.Panic(err) } log.Info("stopped") }