✨ Auto Redirect
All checks were successful
release-nightly / build-docker (push) Successful in 3m33s
All checks were successful
release-nightly / build-docker (push) Successful in 3m33s
This commit is contained in:
parent
90ac125886
commit
9a5c5e9fca
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/config
|
||||
/letsencrypt
|
@ -2,6 +2,7 @@ package hypertext
|
||||
|
||||
import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@ -46,8 +47,23 @@ func RunServer(app *fiber.App, ports []string, securedPorts []string, pem string
|
||||
for _, port := range ports {
|
||||
port := port
|
||||
go func() {
|
||||
if viper.GetBool("hypertext.certificate.redirect") {
|
||||
redirector := fiber.New(fiber.Config{
|
||||
AppName: "RoadSign",
|
||||
ServerHeader: "RoadSign",
|
||||
DisableStartupMessage: true,
|
||||
EnableIPValidation: true,
|
||||
})
|
||||
redirector.All("/", func(c *fiber.Ctx) error {
|
||||
return c.Redirect(strings.ReplaceAll(string(c.Request().URI().FullURI()), "http", "https"))
|
||||
})
|
||||
if err := redirector.Listen(port); err != nil {
|
||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext common ports.")
|
||||
}
|
||||
} else {
|
||||
if err := app.Listen(port); err != nil {
|
||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext tls ports.")
|
||||
log.Panic().Err(err).Msg("An error occurred when listening hypertext common ports.")
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ hypertext:
|
||||
- :81
|
||||
sideload_secured_ports: [ ]
|
||||
certificate:
|
||||
redirect: false
|
||||
sideload_key: ./cert.key
|
||||
sideload_pem: ./cert.pem
|
||||
key: ./cert.key
|
||||
|
Loading…
Reference in New Issue
Block a user