You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remoting already handles CORS; we need to add an API to indicate that a Sitelet endpoint should handle CORS. Maybe with a [<Cors>] attribute on the endpoint?
After looking in more detail into CORS, this is what I now believe would be a good API:
/// Use as an endpoint to indicate that it must check for Cross-Origin Resource Sharing headers./// In addition to matching the same endpoints as 'EndPoint does, this also matches preflight OPTIONS requests./// The corresponding Content should use Content.Cors.typeCors<'EndPoint>=internal{
DefaultAllows :CorsAllows/// If None, then this is a preflight OPTIONS request.
EndPoint :option<'EndPoint>}/// Indicates the "Access-Control-Xyz" headers to send.andCorsAllows={
Origins :seq<string>
Methods :seq<string>
Headers :seq<string>
ExposeHeaders :seq<string>
MaxAge :option<int>
Credentials :bool}moduleContent =/// Respond to a Cross-Origin checked request.valCors:Cors<'EndPoint>->(CorsAllows -> CorsAllows)->('EndPoint -> Async<Content<'OuterEndPoint>>)-> Async<Content<'OuterEndPoint>>
Example use:
typeApiEndPoint=|[<EndPoint "GET /item">] GetItem ofint|[<EndPoint "POST /item"; Json "data">] PostItem ofdata:Data|[<EndPoint "PUT /item"; Json "data">] PutItem ofdata:DatatypeMainEndPoint=|[<EndPoint "GET /">] Home
|[<EndPoint "/">] Api ofCors<ApiEndPoint>letWebsite= Application.MultiPage (fun ctx endpoint ->match endpoint with| Home ->// ...| Api cors ->
Content.Cors cors
<|fun allows ->// [1]{ allows with
Origins =["*"]
Headers =["Content-Type";"Authorization"]}<|function| GetItem it ->// ...| PostItem it ->// ...| PutItem it ->// ...)
[1]: The allows passed here by Content.Cors is a record of empty values, except for Methods which is inferred from the router to be ["GET"; "POST"; "PUT"].
Remoting already handles CORS; we need to add an API to indicate that a Sitelet endpoint should handle CORS. Maybe with a
[<Cors>]
attribute on the endpoint?Requested on the forums.
The text was updated successfully, but these errors were encountered: