MarkLogic HTTP Server: Set up CORS headers
Asked Answered
E

1

6

I am running MarkLogic 7 on a CentOS 6.5 box. I have my HTML/JS application hosted on a MarkLogic HTTP server on the same machine. The application runs on port 8003, and needs to access data through a REST API running on a different port 8007. When I use an AJAX request in my application, I get an error saying

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://172.16.100.104:8003' is therefore not allowed access.  

Has anyone set up MarkLogic for CORS earlier? Any help would be great.

Elder answered 17/6, 2014 at 17:38 Comment(0)
C
3

You can use https://docs.marklogic.com/xdmp:add-response-header to set the Access-Control-Allow-Origin header. You'll have to do that for every endpoint that needs to use cross-site requests: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS has details.

Counterfactual answered 17/6, 2014 at 19:29 Comment(2)
Just for the sake of curiosity, did you know how I could do it if I'm using MarkLogic's inbuilt REST API to access my database?Elder
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: 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.Counterfactual

© 2022 - 2024 — McMap. All rights reserved.