Access-Control-Allow-Origin
Hi: This is probably an extremely newbie-ish question. I'm developing on localhost using MAMP/PHP at port 8888, and basex at port 8984. So I am running into "Cross-Origin Resource Sharing" issues, apparently, when I have the PHP server issue an XMLHttpRequest to the Basex server. I would have thought that this line in my REST GET function %rest:header-param("Access-Control-Allow-Origin", "http://localhost:8888") in my *.xqm file would have solved the problem. Instead, I'm getting this error: 400 (Stopped at /Users/shunting/basex/webapp/restxq.xqm, 395/14: [bxerr:BASX0003] Invalid path template: "http://localhost:8888".) I'm stymied because I don't see how a URL could match a path template in the first place. Is the "Access-Control-Allow-Origin" not a supported parameter? All I want to do is get my two servers on my machine to talk to each other. If this isn't the right way, is there another one? Thank you! * * * Every communication from this account is off the record, unless explicitly put on the record.
Hi Lambert, Welcome to the list.
%rest:header-param("Access-Control-Allow-Origin", "http://localhost:8888")
With the %rest:header-param annotation, you can bind header parameters from the client request to variables. An example: declare %rest:path("/example1") %rest:header-param("Access-Control-Allow-Origin", "{$origin}") function local:example1($origin) { "Origin: " || $origin }; If you want to create a response with this parameter, you need to build a custom response. In BaseX, you can either use the web:response-header function for this, or add the XML response created by this function instead (see [1] and [2]): declare %rest:path("/example2") function local:example2() { web:response-header( map {} , map { "Access-Control-Allow-Origin": "http://localhost:8888" } ), <actual-response/> }; Hope this helps, Christian [1] http://docs.basex.org/wiki/Web_Module#web:response-header [2] http://docs.basex.org/wiki/RESTXQ#Custom_Response
in my *.xqm file would have solved the problem. Instead, I'm getting this error:
400 (Stopped at /Users/shunting/basex/webapp/restxq.xqm, 395/14: [bxerr:BASX0003] Invalid path template: "http://localhost:8888".)
I'm stymied because I don't see how a URL could match a path template in the first place. Is the "Access-Control-Allow-Origin" not a supported parameter?
All I want to do is get my two servers on my machine to talk to each other. If this isn't the right way, is there another one?
Thank you!
* * *
Every communication from this account is off the record, unless explicitly put on the record.
participants (2)
-
Christian Grün -
lambert strether