如何在轨设置访问控制,让原产地的WEBrick? [英] How to set access-control-allow-origin in webrick under rails?

查看:129
本文介绍了如何在轨设置访问控制,让原产地的WEBrick?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个小的Rails应用程序来提供通过将来自其他域的操作xmlhtt prequests内容到另一个站点(这是不可能的,让他们在同一台服务器上运行)。我知道我需要设置访问控制,让原产我的导轨的服务器上,以允许请求的网页访问此材料。

I have written a small rails app to serve up content to another site via xmlhttprequests that will be operating from another domain (it will not be possible to get them running on the same server). I understand I will need to set access-control-allow-origin on my rails server to allow the requesting web page to access this material.

看起来相当有据可查如何与Apache做到这一点,这可能是我会用我一旦部署站点服务器。虽然我发展,虽然我希望只使用的WEBrick,因为我已经习惯使用Rails这样做。是否有配置的WEBrick到轨道内提供相应的HTTP头的方法吗?

It seems fairly well documented how to do this with Apache and this is probably the server I will use once I deploy the site. While I am developing though I hope to just use webrick as I am used to doing with rails. Is there a way of configuring webrick to provide the appropriate http header within rails?

推荐答案

如果你对Rails的2只添加到您的应用程序控制器上。

If you're on Rails 2 just add this to your application contoller.

before_filter :set_access

def set_access
  @response.headers["Access-Control-Allow-Origin"] = "*"
end

显然改变*来的东西少一点开放将是一个不错的主意。

Obviously changing "*" to something a little less open would be a good idea.

这篇关于如何在轨设置访问控制,让原产地的WEBrick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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