MarkLogic - 带有 REST API 的 CORS [英] MarkLogic - CORS with REST API

查看:29
本文介绍了MarkLogic - 带有 REST API 的 CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 MarkLogic 的 Web 应用程序,它从两个源中提取数据,一个文档存储和一个三元组存储,它们都托管在我的 MarkLogic 服务器上.该应用程序使用 MarkLogic 的内置 REST API 来访问这些数据存储.文档存储的 REST API 在端口 8003 上运行,三元组存储的 REST API 在端口 8007 上运行.应用程序托管在文档存储的模块数据库上.现在,当我进行 REST API 调用以提取三重数据时,我收到一条异常消息,指出尚未在服务器端设置access-control-allow-origin"标头.我想知道如何设置它,以便在来自 REST API 的所有响应中将访问控制允许来源"作为*".我已阅读有关 xdmp:add-response-headers 的文档,但我不知道在哪里可以正确使用它.非常感谢所有帮助!

I have a MarkLogic-based web application which pulls data from two sources, a document store and a triple store both hosted on my MarkLogic server. The app uses MarkLogic's built-in REST APIs to access these data stores. The document store's REST API is running on port 8003 and the triple store's REST API is on port 8007. The application is hosted on the modules database of the document store. Now, when I make a REST API call to pull triple data, I get an exception saying the 'access-control-allow-origin' header has not been set at the server side. I would like to know how I can set it up so I get 'access-control-allow-origin' as '*' in all responses from the REST API. I have read the documentation on xdmp:add-response-headers, but I'm not able to figure out where I can use it correctly. All help is much appreciated!

谢谢!

推荐答案

为什么不将文档和三元组保存在同一个数据库中?这样做的能力是 MarkLogic 的强项之一.

Why not keep the documents and triples in the same database? The ability to do that is one of MarkLogic's strengths.

内置的 REST API 端点似乎不支持任何添加任意响应标头的机制.但是,您应该能够在编写 REST 扩展时添加自己的标题:https://docs.marklogic.com/guide/rest-dev/extensions

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

对于内置端点,您可能会考虑通过另一个应用服务器层或透明反向代理来路由请求.无论哪种方式,目标都是重新路由请求,以便浏览器认为两个 REST API 实例位于同一服务器上.

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.

这篇关于MarkLogic - 带有 REST API 的 CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆