2

I'm trying to make a XHR request from my AngularJS instance running on port :8080 to my Structr instance running on port :8082

Thing is, Structr doesn't seem to accept OPTIONS requests on port:8080

Here is the Request header :

OPTIONS /structr/rest/issues HTTP/1.1
Host: localhost:8082
Connection: keep-alive
Cache-Control: max-age=0
Access-Control-Request-Method: GET
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko)        Chrome/37.0.2062.94 Safari/537.36
Access-Control-Request-Headers: accept, -hx-password, -hx-user
Accept: */*
Referer: http://localhost:8080/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,nl;q=0.2

Here is the Response headers from the server:

Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET,PUT,POST
Access-Control-Allow-Origin:http://localhost:8080
Content-Length:44
Content-Type:application/json; charset=utf-8
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Server:Jetty(9.1.4.v20140401)
Set-Cookie:JSESSIONID=1w7n8c71lcbh31s7kwygtat69c;Path=/

The most interesting part IMHO is

Access-Control-Allow-Methods:GET,PUT,POST 

I have to say that my understanding of java and HTTP Requests is really sparse so I don't really feel like digging in the source code...

Or maybe it's a simple Angular thing everyone knows but me...

  • 1
    There are two ways to solve it: #1: Let Structr serve also the AngularJS code. #2: Configure the REST endpoint to accept OPTIONS using a ResourceAccess flag, see http://docs.structr.org/rest-user-guide#Securing REST Endpoints. Hope that helps! – Axel Morgner Sep 18 '14 at 13:16
  • Thanks for the answer. I'll go with solution #1 for now. I'll have a deeper look at #2 later. The documentation about resource flags is saddly a bit too cryptic at first look – Julien Moreau Sep 18 '14 at 14:12
  • I tried Option#2 of @AxelMorgner : assuming i have a schema type 'Issue', I created via the UI a new resourceAccess Node { signature: /issues, flags: 512, id: 6476d9e7747949ae9f4fc56de17e4f8d, type: ResourceAccess, } but my OPTIONS requests are still rejected. Any idea why ? – Julien Moreau Sep 18 '14 at 14:39
  • Update: In the upcoming release 1.1 of Structr, CORS support will be largely improved. See the release notes (https://structr.org/release-notes) for more details, or ask on https://groups.google.com/forum/#!forum/structr – Axel Morgner Nov 13 '14 at 21:01

1 Answers1

1

Thanks to Axel Morgner the answer is :

There are two ways to solve it:

1: Let Structr serve also the AngularJS code.

2: Configure the REST > endpoint to accept OPTIONS using a ResourceAccess flag, see docs.structr.org/rest-user-guide#Securing > REST Endpoints.

Beware that when you create a Schema, structr automatically creates new resourceAccess nodes for the new possibles actions.

  • Julien, is the second option working for you now as well? -Axel. – Axel Morgner Sep 21 '14 at 08:03
  • Axel, in the end, I took option #2 to finally switch back to writing my own NEO4J api in PHP :-( The documentation about API auth in Structr is a bit too sparse for now. I'll be happy to further discuss this if you want (-> twitter) – Julien Moreau Sep 22 '14 at 08:30