Accessing markLogic from another localhost

情到浓时终转凉″ 提交于 2019-12-23 20:13:28

问题


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:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!