feat!: listen to both http & https (#4536)

Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
BoYanZh
2023-06-10 22:26:09 +08:00
committed by Andy Hsu
parent 363e036bf0
commit f646d2a699
6 changed files with 79 additions and 29 deletions

View 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()
}