github.com/joao-fontenele/go-url-shortener@v1.3.4/pkg/api/middleware/cors.go (about) 1 package middleware 2 3 import ( 4 "github.com/valyala/fasthttp" 5 ) 6 7 // Cors is a middleware that sets up cors headers 8 func Cors(next fasthttp.RequestHandler) fasthttp.RequestHandler { 9 return func(ctx *fasthttp.RequestCtx) { 10 ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") 11 ctx.Response.Header.Set( 12 "Access-Control-Allow-Methods", 13 "POST, GET, OPTIONS, PUT, DELETE", 14 ) 15 ctx.Response.Header.Set( 16 "Access-Control-Allow-Headers", 17 "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization", 18 ) 19 20 next(ctx) 21 return 22 } 23 }