2023-04-22 20:39:27 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
|
|
import (
|
2026-01-30 01:00:49 +08:00
|
|
|
"github.com/QuantumNous/new-api/common"
|
2023-04-22 20:39:27 +08:00
|
|
|
"github.com/gin-contrib/cors"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func CORS() gin.HandlerFunc {
|
|
|
|
|
config := cors.DefaultConfig()
|
2023-04-26 14:26:19 +08:00
|
|
|
config.AllowAllOrigins = true
|
2023-04-26 15:27:33 +08:00
|
|
|
config.AllowCredentials = true
|
|
|
|
|
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
|
2023-06-20 22:04:01 +08:00
|
|
|
config.AllowHeaders = []string{"*"}
|
2023-04-22 20:39:27 +08:00
|
|
|
return cors.New(config)
|
|
|
|
|
}
|
2026-01-30 01:00:49 +08:00
|
|
|
|
|
|
|
|
func PoweredBy() gin.HandlerFunc {
|
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
|
c.Header("X-New-Api-Version", common.Version)
|
|
|
|
|
c.Next()
|
|
|
|
|
}
|
|
|
|
|
}
|