开发者

Rails 3 as Rack middleware

Since Rails is fully compliant with Rack I was wandering how I would set up a rackup file so that a Rails application is just a piece of middleware and then a request could hit another app further down the middleware stack.

What I really want is to 开发者_JS百科use a Rails app to handle authentication and authorization for smaller rack-apps later on in the middleware stack, is this possible with Rails 3?


In rack there's a distinction between middleware and an app. You can have a whole stack of middleware, but there's only one app at the end. So you can't do exactly what you are asking.

However, you can share middleware between a rails app and other rack apps. One example of good middleware for authentication is Warden.


Under Rails 3 you have the option of routing to Rack apps from your Rails app.

http://guides.rubyonrails.org/routing.html#routing-to-rack-applications

You could write it such that your authentication/authorization rails app just defined some routes to your rack apps.

match "/app1" => RackApp1
match "/app2" => RackApp2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜