package server import ( "context" "log/slog" "net/http" "github.com/go-chi/chi/v5" "sneak.berlin/go/neoirc/internal/config" ) // NewTestSPAServer creates a Server whose router serves only // the embedded web client. func NewTestSPAServer() *Server { srv := &Server{router: chi.NewRouter()} srv.setupSPA() return srv } // NewTestHTTPServer creates a Server whose router serves // handler at / and whose HTTP server listens on port once // Start is called. func NewTestHTTPServer(port int, handler http.HandlerFunc) *Server { router := chi.NewRouter() router.Get("/", handler) return &Server{ log: slog.New(slog.DiscardHandler), router: router, params: Params{Config: &config.Config{Port: port}}, } } // Start starts the HTTP server, as the start hook does once // the router is built. func (srv *Server) Start() { srv.startHTTP() } // Stop does what the stop hook does. func (srv *Server) Stop(ctx context.Context) { srv.cleanShutdown(ctx) }