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
Copy file name to clipboardExpand all lines: docs/server.md
+15-13Lines changed: 15 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -12,23 +12,25 @@ If your tastes/requirements run more to a standardized multi-format REST server,
12
12
13
13
## Cross Origin Requests
14
14
15
-
By default the browser blocks ajax requests from a server which is different to the current page. To enable such cross origin requests add the `Access-Control-Allow-Origin` and `Access-Control-Allow-Headers` headers to your response as follows.
15
+
By default the browser blocks ajax requests from a server which is different to the current page. To enable such cross origin requests add the `Access-Control-Allow-Origin` and `Access-Control-Allow-Headers` headers to your response as follows. You can use the [`ring-cors`](https://github.com/r0man/ring-cors) library to wrap your routes with customizable CORS middleware.
`Access-Control-Allow-Origin` is the standard header telling the browser to permit a cross origin request. Set it to the server you expect the ajax requests from or a wildcard (less secure). For Google Chrome we must include the header `Access-Control-Allow-Headers` to prevent it stripping the `Content-Type` header from our requests. We must also change the request method from GET or POST to ANY. The browser will actually submit two requests. The first is an OPTIONS request submitted in order to probe the endpoint. The second is the main GET or POST request. Early versions of compojure may not support this correctly.
36
+
`Access-Control-Allow-Origin` isthestandardheadertellingthebrowsertopermitacrossoriginrequest.ForGoogleChromewemustincludetheheader `Access-Control-Allow-Headers` topreventitstrippingthe `Content-Type` headerfromourrequests.Fornon-simplecross-originrequests (e.g. `GET` or `HEAD` requests) thebrowserwillsubmittworequests:a_preflight_andthetargetrequest.Thefirstisan`OPTIONS`requestsubmittedinordertoprobetheendpoint.Thesecondisthemain`GET`or`POST`request.Tounderstandthisprocessbetter, youcanread [Mozilla's guide on Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
0 commit comments