问题
I am trying to use markLogic as a document repository and to write a client that can access it from my localhost (Apache)...
In markLogic, I have created a new REST server (8011) and I now would like to access a markLogic database from the client with a (hopefully simple) HTTP request (actually using jQuery $.ajax). However, the CORS problem rears its ugly head(er). After researching stackoverflow I have modified the $.ajax to include the statement: "crossDomain: true," - however this is not enough.
Do I need to modify my localhost (Apache) in any way?
It may be that I need to modify the response server (markLogic localhost:8011) to: "Access-Control-Allow-Headers: *." ?
How to do this? It seems as though the command should be the markLogic: "xdmp:add-response-header("meta", "description")" -however, where, in what form? Is this a parameter or a pgm statement?
This appears to be common problem as I have run across several questions of this nature - but no answers.
回答1:
Common practice is to do one of two things:
- use a two-tier architecture, in which MarkLogic hosts the JavaScript/HTML/CSS/etc in addition to the REST endpoints that will provide your data.
- use a three-tier architecture where your client (browser) sends its requests to the middle tier, which forwards the request on to MarkLogic.
Either approach is legitimate. You can take a look at Samplestack for an example of the three-tier approach. Current implementation provides a Java middle tier; in the not-too-distant future there should be a Node.js middle tier option. The slush-marklogic-node generator also sets up a three-tier approach, with Node.js as the middle tier (this one is less polished than Samplestack, but pretty straightforward to get going).
回答2:
Since the question mentioned apache, perhaps it's easiest to transparently reverse-proxy the MarkLogic requests through that front-end web server. As far as the browser is concerned that should look like one host and port.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html has full docs but I think it could be as simple as:
ProxyPassReverse /ml8011/ http://localhost:8011/
来源:https://stackoverflow.com/questions/28489966/accessing-marklogic-from-another-localhost