SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

CORS+Support doesn't tell you how to turn on CORS #140

Closed paul-hammant closed 8 years ago

paul-hammant commented 8 years ago

I know it says it is on by default, but I could not tell how.

Here's my app as I build it - https://github.com/paul-hammant-fork/ng_office_plan

I bring up your blog sample app, confirm that that I can make blog posts with it, and query, then bring up my new app on a different port (8081), expecting CORS to 8080 work by default as https://softinstigate.atlassian.net/wiki/display/RH/CORS+Support say it should.

The browser reports:

XMLHttpRequest cannot load http://localhost:8080/seatmap/seats?sort_by=_id. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 404.

Which certainly looks like a CORS error to me.

The blog example mounts the static content on the same port. Sure, I could do the same, but I'm really wanting to make an example that shows off CORS. I checked restheart.yml for the blog example and can't see anything that would turn on CORS that is configured off.

I also can't work out how I get an account for JIRA or Confluence for issues there or comments on pages.

mkjsix commented 8 years ago

Hi @paul-hammant What's the output if you ask the OPTIONS of the involved resources? For example, try: curl -v -u user:password -X OPTIONS http://localhost:8080/seatmap/seats

ujibang commented 8 years ago

CORS is not configurable, meaning that it is always on.

The task to make it configurable is already in the backlog, see https://softinstigate.atlassian.net/browse/RH-37.

to sort out your issue, please use an http client such as httpie, curl or postman to request the same resource and post here the full answer, including the response headers.

the fact that the response code is 404 (not found) makes me thinking that the response is not from the reasheart process.

If you try to get an not existing document from our demo instance:

curl -v  dbapi.io/db/coll/notExistingDocId

You get the CORS headers:

*   Trying 46.101.225.197...
* Connected to dbapi.io (46.101.225.197) port 80 (#0)
> GET /db/coll/ddd HTTP/1.1
> Host: dbapi.io
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Server: nginx/1.9.11
< Date: Mon, 20 Jun 2016 10:44:18 GMT
< Content-Type: application/hal+json
< Content-Length: 167
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< X-Powered-By: restheart.org
< Access-Control-Allow-Credentials: true
< Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By
< 
* Connection #0 to host dbapi.io left intact
{ "_links" : { "self" : { "href" : "/db/coll/ddd"}} , "http status code" : 404 , "http status description" : "Not Found" , "message" : "document 'ddd' does not exist"}
paul-hammant commented 8 years ago

Dammit. I left out the /data/ prefix. UserError.

Thanks for the responses.