Krishna, I can see a couple ways past your problem. As Mike noted, you might be able to work around this by writing your own extension endpoint. Assuming your application is hosted on HTTP App Server A, you could either:
* build an extension on App Server A that will run your query against App Server B's content database (using xdmp:eval()<http://docs.marklogic.com/xdmp:eval>), or * build an extension that provides the request headers you need Alternatively, you could set up a simple middle layer. This is the approach I've taken (and written a couple<http://blog.davidcassel.net/2014/02/demo-catalog/> blog posts<http://blog.davidcassel.net/2014/05/marklogic-angular-and-node-authentication/> about) to build Demo Cat<https://github.com/marklogic/demo-cat> based on a thin node.js layer. With this approach, node.js would host your source code and all requests would go there. When you need to retrieve data from MarkLogic, have the browser layer distinguish between the requests for App Servers A and B somehow in the URL. For instance, the client could request /mla/v1/search versus /mlb/v1/search. Your node layer could then strip out the /mlX part and route the requests accordingly. Actually, it might be easier with an extra parameter: /v1/search?server=A&…. Your node layer would use express<http://expressjs.com/> and do something like this: app.get('/v1*', function(req, res) { var targetPort = getPortForHost(req.query.server); var queryString = req.originalUrl.split('?')[1]; var mlReq = http.request({ hostname: options.mlHost, port: targetPort, method: 'GET', path: req.originalUrl, headers: req.headers, auth: getAuth(options, req.session) }, function(response) { … }; }); You'd write getPortForHost() to return the correct port based on which server the request should be directed to. At that point, node is making the request to MarkLogic, rather than the browser, and Access-Control problem goes away. -- Dave Cassel Vanguard Technical Manager MarkLogic Corporation<http://www.marklogic.com/> Cell: +1-484-798-8720 From: Michael Blakeley <[email protected]<mailto:[email protected]>> Reply-To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Date: Tuesday, June 24, 2014 at 10:56 AM To: MarkLogic Developer Discussion <[email protected]<mailto:[email protected]>> Subject: Re: [MarkLogic Dev General] MarkLogic REST API - CORS Headers The built-in REST API endpoints don't seem to support any mechanism for adding arbitrary response headers. However you should be able to add your own headers when writing a REST extension: https://docs.marklogic.com/guide/rest-dev/extensions For the built-in endpoints you might consider routing requests through another app-server layer, or a transparent reverse proxy. Either way the goal would be to re-route requests so that the browser thinks both REST API instances are on the same server. -- Mike On 23 Jun 2014, at 02:17 , Krishna Chaitanya A <[email protected]<mailto:[email protected]>> wrote: Hello all, I am Krishna, a computer science MSc student at TU Delft in the Netherlands. I am using MarkLogic's inbuilt REST APIs to access two document stores. My web application is hosted in the modules database of one of these stores. When I try accessing the second database from my application, I get the 'No Access-Control-Allow-Origin' error in my browser. I have read the documentation regarding xdmp:add-response-header at https://docs.marklogic.com/xdmp%3aadd-response-header However, I have not been able to figure out where I can use this to enable CORS. Any help on this would be great! Thanks in advance. Regards, Krishna ---- Krishna Chaitanya Akundi MSc Student, Web Information Systems EEMCS - TU Delft The Netherlands _______________________________________________ General mailing list [email protected]<mailto:[email protected]> http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected]<mailto:[email protected]> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
