Change the http listener

This commit is contained in:
Kristoffer Dalby 2022-02-12 16:33:18 +00:00
parent bfc6f6e0eb
commit 59e48993f2

9
app.go
View File

@ -608,15 +608,22 @@ func (h *Headscale) Serve() error {
WriteTimeout: 0, WriteTimeout: 0,
} }
var httpListener net.Listener
if tlsConfig != nil { if tlsConfig != nil {
httpServer.TLSConfig = tlsConfig httpServer.TLSConfig = tlsConfig
httpListener, err = tls.Listen("tcp", h.cfg.Addr, tlsConfig)
} else {
httpListener, err = net.Listen("tcp", h.cfg.Addr)
}
if err != nil {
return fmt.Errorf("failed to bind to TCP address: %w", err)
} }
errorGroup := new(errgroup.Group) errorGroup := new(errgroup.Group)
errorGroup.Go(func() error { return grpcSocket.Serve(socketListener) }) errorGroup.Go(func() error { return grpcSocket.Serve(socketListener) })
errorGroup.Go(func() error { return grpcServer.Serve(grpcListener) }) errorGroup.Go(func() error { return grpcServer.Serve(grpcListener) })
errorGroup.Go(func() error { return httpServer.ListenAndServe() }) errorGroup.Go(func() error { return httpServer.Serve(httpListener) })
log.Info(). log.Info().
Msgf("listening and serving (multiplexed HTTP and gRPC) on: %s", h.cfg.Addr) Msgf("listening and serving (multiplexed HTTP and gRPC) on: %s", h.cfg.Addr)