CORS Middleware for elm-serverless.
{ origin : Reflectable (List String)
, expose : List String
, maxAge : Basics.Int
, credentials : Basics.Bool
, methods : List Serverless.Conn.Request.Method
, headers : Reflectable (List String)
}
Specify all CORS configuration in one record.
A reflectable header value.
A reflectable value can either be
ReflectRequest
derive the headers from the requestExactly
set to a specific valueconfigDecoder : Json.Decode.Decoder Config
Decode CORS configuration from JSON.
methodsDecoder : Json.Decode.Decoder (List Serverless.Conn.Request.Method)
Case-insensitive decode a list of HTTP methods.
reflectableDecoder : Json.Decode.Decoder (Reflectable (List String))
Decode a reflectable value from JSON.
"*"
decodes to ReflectRequest
"foo,bar"
or ["foo", "bar"]
decodes to Exactly ["foo", "bar"]
fromConfig : (config -> Config) -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Set CORS headers according to a configuration record.
This function is best used when the configuration is provided externally and
decoded using configDecoder
. For example, npm rc and AWS Lambda environment
variables can be used as the source of CORS configuration.
allowOrigin : Reflectable (List String) -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-allow-origin
.
ReflectRequest
will reflect the request origin
header, or if absent, will
just be set to *
exposeHeaders : List String -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-expose-headers
.
maxAge : Basics.Int -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-max-age
.
If the value is not positive, the header will not be set.
allowCredentials : Basics.Bool -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-allow-credentials
.
Only sets the header if the value is True
.
allowMethods : List Serverless.Conn.Request.Method -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-allow-methods
.
allowHeaders : Reflectable (List String) -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Sets access-control-allow-headers
.
ReflectRequest
will reflect the request access-control-request-headers
headers
or if absent, it will not set the header at all.
cors : Config -> Serverless.Conn.Conn config model route msg -> Serverless.Conn.Conn config model route msg
Deprecated. Use fromConfig.