Initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"pet-house.com/core/server/web"
|
||||
)
|
||||
|
||||
// Cors
|
||||
func Cors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
c.Header("Access-Control-Allow-Origin", web.CONFIG.Cors.AccessOrigin)
|
||||
c.Header("Access-Control-Allow-Headers", web.CONFIG.Cors.AccessHeaders)
|
||||
c.Header("Access-Control-Allow-Methods", web.CONFIG.Cors.AccessMethods)
|
||||
c.Header("Access-Control-Expose-Headers", web.CONFIG.Cors.AccessExposeHeaders)
|
||||
c.Header("Access-Control-Allow-Credentials", web.CONFIG.Cors.AccessCredentials)
|
||||
|
||||
if method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/unrolled/secure"
|
||||
)
|
||||
|
||||
// LoadTls
|
||||
func LoadTls() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
middleware := secure.New(secure.Options{
|
||||
SSLRedirect: true,
|
||||
SSLHost: "127.0.0.1:443",
|
||||
})
|
||||
err := middleware.Process(c.Writer, c.Request)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user