Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCorsHandler ¶
GetCorsHandler returns a CORS handler configured based on the environment and port. It follows the principle of least privilege by restricting allowed origins based on environment, limits headers to a minimum of "Content-Type" and "Authorization" plus any additional headers provided, and allows only essential HTTP methods. Supplied Headers need not be case-sensitive and are normalized and sorted to ensure compatibility with the rs/cors library. It will return an error if the environment is not mapped to a URL. Multiple URL's can be provided per environment via the UrlMap.
GetCorsHandler(env.Development, UrlMap{env.Development: []string{"http://localhost:8081"}}, []string{"X-Custom-Header"})
Allows origin "http://localhost:8081" with Allowed-Headers: "Content-Type", "Authorization", "X-Custom-Header"
GetCorsHandler(env.Staging, UrlMap{env.Staging: []string{"https://staging.example.com"}}, []string{})
Allows origin "https://staging.example.com" with Allowed-Headers: "Content-Type", "Authorization"