feat!: listen to both http & https (#4536)
Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
21
server/middlewares/https.go
Normal file
21
server/middlewares/https.go
Normal file
@ -0,0 +1,21 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func ForceHttps(c *gin.Context) {
|
||||
if c.Request.TLS == nil {
|
||||
host := c.Request.Host
|
||||
// change port to https port
|
||||
host = strings.Replace(host, fmt.Sprintf(":%d", conf.Conf.Port), fmt.Sprintf(":%d", conf.Conf.HttpsPort), 1)
|
||||
c.Redirect(302, "https://"+host+c.Request.RequestURI)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
Reference in New Issue
Block a user