2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 12:40:25 +08:00

feat: http自动跳转https

This commit is contained in:
耗子
2024-10-26 21:26:14 +08:00
parent ba819a5a9c
commit b2845fba15
3 changed files with 9 additions and 2 deletions

1
go.mod
View File

@@ -54,6 +54,7 @@ require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/bddjr/hlfhr v1.1.2 // indirect
github.com/bodgit/plumbing v1.2.0 // indirect
github.com/bodgit/sevenzip v1.3.0 // indirect
github.com/bodgit/windows v1.0.0 // indirect

2
go.sum
View File

@@ -27,6 +27,8 @@ github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b h1:1iVxCglpEJ/kq48
github.com/TheTNB/acmez/v2 v2.0.0-20241025203320-cc718c4c870b/go.mod h1:pQ1ysaDeGrIMvJ9dfJMk5kJNkn7L2sb3UhyrX6Q91cw=
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bddjr/hlfhr v1.1.2 h1:Cn1H16Az9UFlw/S2oHkqWPrO24s61pJvfVyqgYQLNeE=
github.com/bddjr/hlfhr v1.1.2/go.mod h1:oyIv4Q9JpCgZFdtH3KyTNWp7YYRWl4zl8k4ozrMAB4g=
github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho=
github.com/beevik/ntp v1.4.3/go.mod h1:Unr8Zg+2dRn7d8bHFuehIMSvvUYssHMxW3Q5Nx4RW5Q=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=

View File

@@ -7,6 +7,7 @@ import (
"net/http"
"path/filepath"
"github.com/bddjr/hlfhr"
"github.com/go-chi/chi/v5"
"github.com/TheTNB/panel/internal/app"
@@ -26,11 +27,14 @@ func initHttp() {
route.Ws(app.Http)
apps.Boot(app.Http)
srv := &http.Server{
srv := hlfhr.New(&http.Server{
Addr: fmt.Sprintf(":%d", app.Conf.MustInt("http.port")),
Handler: http.AllowQuerySemicolons(app.Http),
MaxHeaderBytes: 2048 << 20,
}
})
srv.HttpOnHttpsPortErrorHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hlfhr.RedirectToHttps(w, r, http.StatusTemporaryRedirect)
})
if app.Conf.Bool("http.tls") {
srv.TLSConfig = &tls.Config{