Middleware guides
Middleware - CORS
Detailed guide to Kern CORS middleware, including basic and advanced CORS configuration for browser-based APIs.
Kern.CORS and Kern.CORSWithConfig
Use CORS middleware when browser clients call your API from another origin.
Signatures
func CORS(origins []string) MiddlewareFunc
func CORSWithConfig(config CORSConfig) MiddlewareFuncBasic example
app.Use(kern.CORS([]string{"https://app.example.com"}))Advanced example
app.Use(kern.CORSWithConfig(kern.CORSConfig{
AllowOrigins: []string{"https://app.example.com"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowHeaders: []string{"Content-Type", "Authorization"},
ExposeHeaders: []string{"X-Request-ID"},
AllowCredentials: true,
MaxAge: 86400,
}))