简体   繁体   English

Facebook WebGL 游戏 + Facebook 简单托管 + CORS。 可能的?

[英]Facebook WebGL Game + Facebook Simple Hosting + CORS. Possible?

Note: Solved - question makes no sense, my understanding of CORS was incorrect and lead me to ask this question.注意:已解决 - 问题没有意义,我对 CORS 的理解不正确,导致我提出这个问题。

The answer is simple as pointed out by @CBroe below - CORS needs to be configured on the game server (in the example in this qestion).正如下面@CBroe 所指出的,答案很简单 - 需要在游戏服务器上配置 CORS(在此问题的示例中)。

I have a Facebook WebGL game that I'm wanting to host using Facebook's simple hosting ( https://developers.facebook.com/docs/games/services/contenthosting/ ).我有一个 Facebook WebGL 游戏,我想使用 Facebook 的简单托管 ( https://developers.facebook.com/docs/games/services/contenthosting/ ) 托管。

Is it possible to use Facebook's Simple Hosting for a WebGL game and still contact my web server (mygamedomain.com)?是否可以将 Facebook 的 Simple Hosting 用于 WebGL 游戏并仍然联系我的网络服务器 (mygamedomain.com)? Is there somewhere in the FB app config to specify domains to allow? FB 应用程序配置中是否有指定允许的域?

Is the only way to get around this to serve the game from mygamedomain.com also?也是从 mygamedomain.com 为游戏提供服务的唯一方法吗?

I'd really like to avoid serving the game from my webserver if possible.如果可能的话,我真的很想避免从我的网络服务器提供游戏。

Any ideas or suggestions?有什么想法或建议吗?

Not doing so will generate an error as expected:不这样做会产生预期的错误:

XMLHttpRequest cannot load https://mygamedomin.com/mygame.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://apps-1287636812638.apps.fbsbx.com' is therefore not allowed access.

Just to be clear as there seems to be some confusion:只是为了清楚,因为似乎有些混乱:

  • Game is hosted by facebook using their "Simple Hosting" service, not on my own server, .游戏由facebook使用他们的“简单托管”服务托管,而不是在我自己的服务器上。
  • I know CORS is the solution - the question is - does Facebook allow/support this?我知道 CORS 是解决方案——问题是——Facebook 是否允许/支持这个? If so where do I configure the domains to allow.如果是这样,我在哪里配置域以允许。
  • If this was on my own server I the answer is trivial - CORS.如果这是在我自己的服务器上,我的答案是微不足道的 - CORS。 But it's not.但事实并非如此。
  • There are hacks to circumvent cross-origin restrictions - I'm not looking for these.有一些黑客可以绕过跨域限制——我不是在寻找这些。 There's plenty of resources already covering these.有很多资源已经涵盖了这些。

Edit: changed the title to more accurately reflect my question.编辑:更改标题以更准确地反映我的问题。

CORS is the solution to your problem here. CORS您问题的解决方案。

This question/the answer is not Facebook specific - the issue would be the same with any other domain serving your content, that is different from your own.这个问题/答案不是 Facebook 特有的——这个问题与为您的内容提供服务的任何其他域相同,与您自己的域不同。

Your client-side code is hosted under the Facebook domain, and tries to make a request to your domain - that is the cross-domain part.您的客户端代码托管在 Facebook 域下,并尝试向您的域发出请求 - 这是跨域部分。 Your domain is the party that holds the power to either allow or deny this request - by default, it would be denied, but by responding with the appropriate header, your server can signal to the browser, "yes, that's ok, he [your code running under facebook.com] is one of the good guys ..."您的域是有权允许或拒绝此请求的一方 - 默认情况下,它会被拒绝,但是通过响应适当的标头,您的服务器可以向浏览器发出信号,“是的,没关系,他 [您的在 facebook.com 下运行的代码] 是好人之一......”

So you need to configure this on your server, that you want to make the request to .所以你需要在你的服务器上配置它,你想.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM