Last active
December 19, 2015 13:19
-
-
Save psykidellic/5961665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url: http://localhost:3000/signin from: https://localhost:3001/signin | |
| $.ajax( | |
| type: "POST" | |
| url: url | |
| data: | |
| user: | |
| password: password | |
| login: email | |
| contentType: 'text/plain' | |
| crossDomain: true | |
| headers: | |
| 'X-Requested-With': 'XMLHttpRequest' | |
| success: (data) => | |
| console.log("Redirecting after login " + data) | |
| error: (error) => | |
| console.log(error) | |
| ) |
Author
Author
Rails controller:
before_filter :cors_preflight_check
If this is a preflight OPTIONS request, then short-circuit the
request, return only the necessary headers and return an empty
text/plain.
def cors_preflight_check
if request.method == :options
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, Content-Type'
response.headers['Access-Control-Max-Age'] = '1728000'
render :text => '', :content_type => 'text/plain'
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OPTIONS /api/v1/signIn HTTP/1.1
Host: localhost:3001
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://localhost:3000
Access-Control-Request-Method: POST
Access-Control-Request-Headers: x-requested-with
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-UA-Compatible: IE=Edge
ETag: "0933f08f904f9fbf4cbfc0c9df195d88"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: _foo_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJTE1MjlhZTZlMzQxMjhiYmU5NGQxY2M4ZWM1MWI5OTdjBjsAVEkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBmkGSSIiJDJhJDEwJGhJanlPMFFCakkzOC5Fb3ZmckdUcmUGOwBU--36a88a8109cee9d2777efd75e3f6258b04380d3a; path=/; HttpOnly
X-Request-Id: 15322ff3510bce36a719eb1caca0b458
X-Runtime: 0.086458
Connection: close
Server: thin 1.5.1 codename Straight Razor