rack-middleware

Reloading rails middleware without restarting the server in development

做~自己de王妃 提交于 2019-12-05 03:42:42
I have a rails 4 app with middleware located at lib/some/middleware.rb which is currently injected into the stack though an initializer like so: MyApp::Application.configure.do |config| config.middleware.use 'Some::Middleware' end Unfortunately, any time I change something I need to restart the server. How can I reload it on each request in development mode? I've seen similar questions about reloading lib code with either autoloading or wrapping code in a to_prepare block but I'm unsure how that could be applied in this scenario. Thanks, - FJM Update #1 If I try to delete the middleware and

Adding a custom middleware to Rails 4

余生颓废 提交于 2019-12-05 00:58:05
I have a Rails 4 sample project (Blog) and I have created a simple middleware called 'request_timer' in config/initializers/request_timer.rb #config/initializers/request_timer.rb class RequestTimer def initialize(app) @app = app end def call(env) start_time = Time.now status, headers, response = @app.call(env) stop_time = Time.now [status, headers, response.body] end end and I have added my middleware in config/application.rb in two ways 1 ) Adding as a constant #config/application.rb module Blog class Application < Rails::Application config.middleware.use RequestTimer end end this way when I

Hello World rack middleware with rails 3: how to process body of all requests

孤者浪人 提交于 2019-12-04 23:52:44
问题 i want to try out a simple rack middleware "hello world", but i seem to get stuck. it looks like the main sytax changed, since some examples use this code: require 'rack/utils' class FooBar def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) body.body << "\nHi from #{self.class}" [status, headers, body] end end produces an error: undefined method `<<' for #<ActionDispatch::Response:0x103f07c48> even when i look at other codes out there, i cannot seem to get

Sinatra rack middleware hijacks '/' root url

天涯浪子 提交于 2019-12-04 22:23:36
I'm trying to use a Sinatra app as middleware in my Rails app. I've tested a basic Sinatra app in the /lib folder of the Rails app, use d the middleware and set a route. That worked fine. What I want to be able to do is extract the Sinatra app and include it as a gem. That way I can run the Sinatra app independently, or use it in multiple Rails apps. Sinatra App # myrackapp/lib/myrackapp.rb module Myrackapp class Application < Sinatra::Base set :root, File.dirname(__FILE__) get "/" do "Rack Home" end get '/rackroute' do "Hello, Rack Page" end end end Myrackapp also has a gemspec – nothing

Hello World rack middleware with rails 3: how to process body of all requests

三世轮回 提交于 2019-12-03 15:17:20
i want to try out a simple rack middleware "hello world", but i seem to get stuck. it looks like the main sytax changed, since some examples use this code: require 'rack/utils' class FooBar def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) body.body << "\nHi from #{self.class}" [status, headers, body] end end produces an error: undefined method `<<' for #<ActionDispatch::Response:0x103f07c48> even when i look at other codes out there, i cannot seem to get them running with rails 3.0.3. here are my concrete questions: how can i get a simple rack middleware

Apartment current_tenant resets to 'public' after failed devise login

半城伤御伤魂 提交于 2019-12-02 05:34:32
问题 I use Devise for authentication and Apartment for multi-tenancy support on a SAAS app. After a failed login, devise "redirects" to the login page (Users::SessionsController#new) and the value of Apartment::Tenant.current which was previously set in a TenantElevator middleware goes back to its default value of "public". This is happening because Devise isn't actally redirecting to the login page but calling the FailureApp (which renders the login page) with a new rack env and returning its

Apartment current_tenant resets to 'public' after failed devise login

时光总嘲笑我的痴心妄想 提交于 2019-12-02 00:53:50
I use Devise for authentication and Apartment for multi-tenancy support on a SAAS app. After a failed login, devise "redirects" to the login page (Users::SessionsController#new) and the value of Apartment::Tenant.current which was previously set in a TenantElevator middleware goes back to its default value of "public". This is happening because Devise isn't actally redirecting to the login page but calling the FailureApp (which renders the login page) with a new rack env and returning its response. The new rack app doesn't have TenantElevator middleware so the tenant isn't set within the rack

How to determine if Rails is running from CLI, console or as server?

爷,独闯天下 提交于 2019-11-28 21:11:18
I have a middleware for announcing my application on the local network app using Bonjour , but it's also announcing the service when Rails is invoked from rake or through the console. I'd like to exclude these cases, and only use the Bonjour middleware when Rails is running as a server. The middleware configuration accepts a proc to exclude middlewares under certain conditions using a proc : config.middleware.insert_before ActionDispatch::Static, Rack::SSL, :exclude => proc { |env| env['HTTPS'] != 'on' } But how do I determine if Rails was invoked from the CLI, console or as a server? Peeking

How to determine if Rails is running from CLI, console or as server?

倖福魔咒の 提交于 2019-11-27 12:48:52
问题 I have a middleware for announcing my application on the local network app using Bonjour, but it's also announcing the service when Rails is invoked from rake or through the console. I'd like to exclude these cases, and only use the Bonjour middleware when Rails is running as a server. The middleware configuration accepts a proc to exclude middlewares under certain conditions using a proc : config.middleware.insert_before ActionDispatch::Static, Rack::SSL, :exclude => proc { |env| env['HTTPS'