mirror of https://github.com/gofiber/fiber.git
parent
3242e5b151
commit
074e1f9c9c
33
app.go
33
app.go
|
@ -11,6 +11,8 @@ package fiber
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -540,8 +542,7 @@ func (app *App) Listener(ln net.Listener) error {
|
||||||
if !app.config.DisableStartupMessage {
|
if !app.config.DisableStartupMessage {
|
||||||
app.startupMessage(ln.Addr().String(), false, "")
|
app.startupMessage(ln.Addr().String(), false, "")
|
||||||
}
|
}
|
||||||
|
// Start listening
|
||||||
// TODO: Detect TLS
|
|
||||||
return app.server.Serve(ln)
|
return app.server.Serve(ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,6 +568,34 @@ func (app *App) Listen(addr string) error {
|
||||||
return app.server.Serve(ln)
|
return app.server.Serve(ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) ListenTLS(addr, certFile, keyFile string) error {
|
||||||
|
// Check for valid cert/key path
|
||||||
|
if len(certFile) == 0 && len(keyFile) == 0 {
|
||||||
|
return errors.New("provide a valid cert or key path")
|
||||||
|
}
|
||||||
|
// Prefork is supported
|
||||||
|
if app.config.Prefork {
|
||||||
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot load TLS key pair from certFile=%q and keyFile=%q: %s", certFile, keyFile, err)
|
||||||
|
}
|
||||||
|
config := &tls.Config{
|
||||||
|
PreferServerCipherSuites: true,
|
||||||
|
Certificates: []tls.Certificate{
|
||||||
|
cert,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return app.prefork(addr, config)
|
||||||
|
}
|
||||||
|
// Setup listener
|
||||||
|
ln, err := net.Listen("tcp4", addr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Start listening
|
||||||
|
return app.server.ServeTLS(ln, certFile, keyFile)
|
||||||
|
}
|
||||||
|
|
||||||
// Config returns the app config as value ( read-only ).
|
// Config returns the app config as value ( read-only ).
|
||||||
func (app *App) Config() Config {
|
func (app *App) Config() Config {
|
||||||
return app.config
|
return app.config
|
||||||
|
|
Loading…
Reference in New Issue