MeteorJS REST API从外部URL(使用CollectionsFS) [英] MeteorJS REST API from External URL (using CollectionsFS)

查看:403
本文介绍了MeteorJS REST API从外部URL(使用CollectionsFS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用CollectionFS的http-methods包实现了一个API( https:// github。 com / CollectionFS / Meteor-http-methods



但是,此API需要从另一个(外部)域调用,这意味着我们的API服务器必须响应预检OPTIONS方法,并将Access-Control-Allow-Origin标头设置为*或外部域。



不幸的是,建议,主要针对Meteor的移动应用/ cordova支持。



有没有建议?



PS - 请避免使用未实现API和使用DDP的建议,因为它们在这种情况下不相关。

解决方案

程序包允许在方法体中使用 this.addHeader(name,value)设置标头。



默认情况下,为Cordova(http://meteor.local)设置一个 Access-Control-Allow-Origin



因此,设置 this.addHeader(Access-Control-Allow-Origin ,http://your.domain.com)将允许 http://your.domain.com 调用API。 / p>

We've implemented an API using CollectionFS' http-methods package (https://github.com/CollectionFS/Meteor-http-methods)

However, this API needs to be called from another (external) domain, which means our API Server must respond to a preflight OPTIONS methods and have the Access-Control-Allow-Origin header set to either * or the external domain.

Unfortunately, while the Internet if filled with various suggestions, mainly for Meteor's mobile app/cordova support. I could not find a working solution when trying to access an API endpoint via an external domain.

Any suggestions?

P.S - Please avoid suggestions that hit on NOT implementing an API and using DDP instead, as they are not relevant in this case.

解决方案

The package allows setting headers using this.addHeader(name, value) in the method body.

By default, there is an Access-Control-Allow-Origin header set for Cordova ("http://meteor.local"), and adding such header will replace it.

So, setting this.addHeader("Access-Control-Allow-Origin", "http://your.domain.com") will allow http://your.domain.com to call the API.

这篇关于MeteorJS REST API从外部URL(使用CollectionsFS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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