Skip to content

cors

cors adds CORS response headers and handles preflight requests.

yaml
server:
  http:
    middlewares:
      cors_api:
        cors:
          allow_origins:
            - https://app.example.com
          allow_methods:
            - GET
            - POST
          allow_headers:
            - Authorization
            - Content-Type
          expose_headers:
            - X-Request-Id
          max_age: 600
          allow_credentials: true
FieldDefaultDescription
allow_origins['*']Allowed origins. * and ? wildcards are supported.
allow_methodsGET,HEAD,PUT,PATCH,POST,DELETEMethods sent in preflight responses.
allow_headersHeaders allowed in preflight responses. When empty, requested headers are echoed.
expose_headersHeaders exposed to browser JavaScript.
max_age0Preflight cache duration in seconds.
allow_credentialsfalseSet Access-Control-Allow-Credentials: true.
unsafe_wildcard_origin_with_allow_credentialsfalseReflect any origin when credentials and * are both used. This is unsafe.