使用 Javascript、HTML5 的跨域 REST 代理

发布于 2024-09-05 16:11:07 字数 496 浏览 4 评论 0原文

我正在编写一项服务(例如 service.com),该服务为在 IFrames 内运行的外部应用程序提供 REST API。 (这些应用程序由 service.com 外部的域托管)。

我正在计划一个 javascript 客户端库,供应用程序向 service.com REST API 发出纯 javascript 请求 - 基本上使用 postMessage 和一些临时封装我的 API 调用跨框架来回获取消息(从 external-app.com IFrame --> service.com REST API,然后返回到 IFrame 并返回响应)。

我的问题:是否有任何强大的通用 JavaScript 库来完成我需要的跨域 REST 请求代理,或者< strong>我应该从头开始破解它吗?

I'm writing a service (say, service.com) that provides a REST API to external apps running inside of IFrames. (These apps are hosted from domains outside the service.com).

I'm planning a javascript client library for the apps to make pure-javascript requests to the service.com REST API -- basically using postMessage and some ad-hoc encapsulation of my API calls to get messages back and forth across frames (from the outside-app.com IFrame --> service.com REST API, and back to the IFrame with a response).

My question: is there any robust, general-purpose javascript library to accomplish the kind of cross-domain REST request proxying I need, or should I just hack it from scratch?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莫多说 2024-09-12 16:11:07

您听说过源访问控制吗?您只需在 .htaccess 中设置它即可允许跨域的 XHR 请求。

Header Set Access-Control-Allow-Origin *

在这种情况下,您不需要标准 AJAX 组件以外的任何东西。

Have you heard about origin access control? You can just set it in your .htaccess to allow XHR requests across domains.

Header Set Access-Control-Allow-Origin *

In which case, you don't need anything past your standard AJAX components.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文