cors.go 527 B

1234567891011121314151617181920212223
  1. package middleware
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "github.com/gin-contrib/cors"
  5. "github.com/gin-gonic/gin"
  6. )
  7. func CORS() gin.HandlerFunc {
  8. config := cors.DefaultConfig()
  9. config.AllowAllOrigins = true
  10. config.AllowCredentials = true
  11. config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
  12. config.AllowHeaders = []string{"*"}
  13. return cors.New(config)
  14. }
  15. func PoweredBy() gin.HandlerFunc {
  16. return func(c *gin.Context) {
  17. c.Header("X-New-Api-Version", common.Version)
  18. c.Next()
  19. }
  20. }