[FEATURE] Add IPv6 support (#1196)

pull/1207/head
Amir Zarrinkafsh 2020-07-16 16:36:37 +10:00 committed by GitHub
parent ea1fae6491
commit bcd6a6aa45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -1,7 +1,7 @@
package server package server
import ( import (
"fmt" "net"
"os" "os"
"strconv" "strconv"
@ -133,13 +133,18 @@ func StartServer(configuration schema.Configuration, providers middlewares.Provi
WriteBufferSize: configuration.Server.WriteBufferSize, WriteBufferSize: configuration.Server.WriteBufferSize,
} }
addrPattern := fmt.Sprintf("%s:%d", configuration.Host, configuration.Port) addrPattern := net.JoinHostPort(configuration.Host, strconv.Itoa(configuration.Port))
listener, err := net.Listen("tcp", addrPattern)
if err != nil {
logging.Logger().Fatalf("Error initializing listener: %s", err)
}
if configuration.TLSCert != "" && configuration.TLSKey != "" { if configuration.TLSCert != "" && configuration.TLSKey != "" {
logging.Logger().Infof("Authelia is listening for TLS connections on %s%s", addrPattern, configuration.Server.Path) logging.Logger().Infof("Authelia is listening for TLS connections on %s%s", addrPattern, configuration.Server.Path)
logging.Logger().Fatal(server.ListenAndServeTLS(addrPattern, configuration.TLSCert, configuration.TLSKey)) logging.Logger().Fatal(server.ServeTLS(listener, configuration.TLSCert, configuration.TLSKey))
} else { } else {
logging.Logger().Infof("Authelia is listening for non-TLS connections on %s%s", addrPattern, configuration.Server.Path) logging.Logger().Infof("Authelia is listening for non-TLS connections on %s%s", addrPattern, configuration.Server.Path)
logging.Logger().Fatal(server.ListenAndServe(addrPattern)) logging.Logger().Fatal(server.Serve(listener))
} }
} }