mirror of
https://github.com/tuxdotrs/trok.git
synced 2026-09-19 15:09:03 +05:30
refactor(server): remove autocert tls setup
This commit is contained in:
@@ -1,14 +1,12 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/tuxdotrs/trok/internal/web"
|
"github.com/tuxdotrs/trok/internal/web"
|
||||||
"golang.org/x/crypto/acme/autocert"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrokWeb struct {
|
type TrokWeb struct {
|
||||||
@@ -36,29 +34,7 @@ func (t *TrokWeb) Start() {
|
|||||||
Browse: true,
|
Browse: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
cfg := t.GetTLSCert()
|
log.Panic().Err(t.app.Listen(t.addr)).Msg("unable to start trok webserver")
|
||||||
|
|
||||||
ln, err := tls.Listen("tcp", t.addr, 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() {
|
func (t *TrokWeb) Stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user