gleam/http/cors

Functions

pub fn middleware(origins allowed_origins: List(String), methods allowed_methods: List(
    Method,
  ), headers allowed_headers: List(String)) -> fn(
  fn(Request(a)) -> Response(BitBuilder),
) -> fn(Request(a)) -> Response(BitBuilder)

A middleware that adds CORS headers to responses based on the given configuration.

Examples

service
|> cors.middleware(
  origins: ["https://staging.example.com", "http://localhost:8000"],
  methods: [Get, Post, Delete],
  headers: ["Authorization", "Content-Type"],
)