mirror of
https://github.com/tuxdotrs/trok.git
synced 2025-07-06 20:06:34 +05:30
feat: add automatic ssl certificate
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/tuxdotrs/trok/internal/web"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
)
|
||||
|
||||
type TrokWeb struct {
|
||||
@ -33,7 +36,29 @@ func (t *TrokWeb) Start() {
|
||||
Browse: true,
|
||||
}))
|
||||
|
||||
t.app.Listen(t.addr)
|
||||
cfg := t.GetTLSCert()
|
||||
|
||||
ln, err := tls.Listen("tcp", ":443", cfg)
|
||||
if err != nil {
|
||||
log.Panic().Msgf("unable to start trok webserver: %v", err)
|
||||
}
|
||||
|
||||
t.app.Listener(ln)
|
||||
}
|
||||
|
||||
func (t *TrokWeb) GetTLSCert() *tls.Config {
|
||||
m := &autocert.Manager{
|
||||
Prompt: autocert.AcceptTOS,
|
||||
HostPolicy: autocert.HostWhitelist("trok.cloud"),
|
||||
Cache: autocert.DirCache("./certs"),
|
||||
}
|
||||
|
||||
return &tls.Config{
|
||||
GetCertificate: m.GetCertificate,
|
||||
NextProtos: []string{
|
||||
"http/1.1", "acme-tls/1",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TrokWeb) Stop() {
|
||||
|
Reference in New Issue
Block a user