限制对特定子域的某些调用?
我正在组合一个 API,只需要 JSON 和可从 api
子域访问 XML 调用。
但除了限制响应格式之外,我还想限制某些控制器操作到该子域。
那么,如何将某些控制器、操作甚至响应格式限制到特定的子域?
I'm putting together an API and only want the JSON & XML calls to be accessible from the api
subdomain.
But in addition to limiting a response format, there are also certain controller actions that I'd want to restrict to that subdomain as well.
So, how can I restrict certain controllers, actions and even response formats to a specific subdomain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以在这样的路由中限制它:
我认为你也可以使用
:constraints
的过程或传递一个真正的约束类。http://guides.rubyonrails.org/routing.html#request-based-constraints
you can restrict this in the routes like this:
i think that you can also use a proc for
:constraints
or pass a real constraint-class.http://guides.rubyonrails.org/routing.html#request-based-constraints
如果我理解正确的话,我相信你可以通过 paths.rb 做你想做的事,如下所示:
If I understand correctly I believe you can do what you want through routes.rb, like so: