✨ 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
|
/config
|
||||||
|
/letsencrypt
|
@ -2,6 +2,7 @@ package hypertext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@ -46,8 +47,23 @@ func RunServer(app *fiber.App, ports []string, securedPorts []string, pem string
|
|||||||
for _, port := range ports {
|
for _, port := range ports {
|
||||||
port := port
|
port := port
|
||||||
go func() {
|
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 {
|
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.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@ debug:
|
|||||||
hypertext:
|
hypertext:
|
||||||
sideload_ports:
|
sideload_ports:
|
||||||
- :81
|
- :81
|
||||||
sideload_secured_ports: []
|
sideload_secured_ports: [ ]
|
||||||
certificate:
|
certificate:
|
||||||
|
redirect: false
|
||||||
sideload_key: ./cert.key
|
sideload_key: ./cert.key
|
||||||
sideload_pem: ./cert.pem
|
sideload_pem: ./cert.pem
|
||||||
key: ./cert.key
|
key: ./cert.key
|
||||||
@ -14,7 +15,7 @@ hypertext:
|
|||||||
max_qps: -1
|
max_qps: -1
|
||||||
ports:
|
ports:
|
||||||
- :8000
|
- :8000
|
||||||
secured_ports: []
|
secured_ports: [ ]
|
||||||
paths:
|
paths:
|
||||||
configs: ./config
|
configs: ./config
|
||||||
performance:
|
performance:
|
||||||
|
Loading…
Reference in New Issue
Block a user