github.com/profzone/eden-framework@v1.0.10/pkg/courier/transport_http/cors.go (about)

     1  package transport_http
     2  
     3  import (
     4  	"net/http"
     5  	"strconv"
     6  	"strings"
     7  	"time"
     8  
     9  	"github.com/profzone/eden-framework/pkg/courier/httpx"
    10  )
    11  
    12  func setCORS(headers *http.Header) {
    13  	headers.Set("Access-Control-Allow-Credentials", "false")
    14  	headers.Set("Access-Control-Allow-Origin", "*")
    15  	headers.Set("Access-Control-Allow-Methods", strings.Join([]string{
    16  		http.MethodGet,
    17  		http.MethodPut,
    18  		http.MethodPost,
    19  		http.MethodHead,
    20  		http.MethodDelete,
    21  		http.MethodPatch,
    22  	}, ","))
    23  	headers.Set("Access-Control-Allow-Headers", strings.Join([]string{
    24  		"Origin",
    25  		httpx.HeaderContentType,
    26  		"Content-Length",
    27  		"Authorization",
    28  		"AppToken",
    29  		"AccessKey",
    30  	}, ","))
    31  	headers.Set("Access-Control-Max-Age", strconv.FormatInt(int64(12*time.Hour/time.Second), 10))
    32  }