-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
When a site makes a cross-origin ajax request, the browser makes 2 calls to the destination URL under the hood. The first call is a request with the OPTIONS HTTP verb, to which the webserver sends back appropriate Access-Control headers which determine whether the webserver will accept the next request. This is followed by the actual request.
When mocking such a cross origin request, we need to populate mirage with two templates. Below is an example of what we had to do for a simple POST request for example:
mirage.put('/api/endpoint', "") do
http_method :options
headers "Access-Control-Allow-Headers" => "Origin, X-Requested-With, Content-Type",
"Access-Control-Allow-Methods" => "POST",
"Access-Control-Allow-Origin" => "*"
end
mirage.put('/api/endpoint', {response: :body}.to_json) do
http_method :post
endMight be worth having a DSL method for doing it in one go. If not then might be worth having it somewhere in the README as a recipe for front-end cross-origin testing.
Metadata
Metadata
Assignees
Labels
No labels