rack

Redirect logger output for a specific controller in Rails 4

好久不见. 提交于 2019-12-20 18:35:50
问题 I've built a solution based on the answer in my previous question Redirect logger output for a specific controller in Rails 3 for Rails 3. It works great however now I am trying to apply the same middleware based solution to a Rails 4 project but there are some differences keeping the same solution from working. The Rails 3 solution: module MyApp class LoggerMiddleware REPORTS_API_CONTROLLER_PATH = %r|\A/api/v.*/reports.*| REPORTS_API_CONTROLLER_LOGFILE = "reports_controller.log" def

Sinatra, Rack::Test, and Conditional GET requests

巧了我就是萌 提交于 2019-12-20 17:28:37
问题 I've got a Sinatra 1.2.0 app that is doing Last-Modified validation caching with Rack::Cache. Things are working great-- I call last_modified in my route body and if the cache has an up-to-date copy, the rest of the execution halts, my app responds to the cache with 304 Not Modified, and the cache serves the cached page without having to generate a new one. My issue is in trying to write tests for this process. Using Rack::Test and Minitest::Spec, I'm simulating the cache's conditional Get

faye ruby client is not working

≡放荡痞女 提交于 2019-12-20 10:56:02
问题 I am using faye on my Rails 2.1 app. And after testing and fixing many things faye ruby client is not working. This is my server code. require 'faye' server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45) EM.run { thin = Rack::Handler.get('thin') thin.run(server, :Port => 9292) server.bind(:subscribe) do |client_id, channel| puts "[ SUBSCRIBE] #{client_id} -> #{channel}" end server.bind(:unsubscribe) do |client_id, channel| puts "[UNSUBSCRIBE] #{client_id} -> #{channel}" end server

Adding `params` and `session` and `env` to Object

点点圈 提交于 2019-12-20 04:40:52
问题 In a gem I'm writing I am trying to add the rack methods params , session , and env to Object so that they can be accessed and modified by the user of the gem. I have tried using Object.instance_variable_set and Object.instance_variable_get to add the variables to Object and then set them again by retrieving them from Object . I have been using the Rack::Request.new(env) interface to do this. The only problem is that it seems to be impossible to set params and session through this object.

Ruby on rails - rack middleware exclude - is it possible?

有些话、适合烂在心里 提交于 2019-12-20 02:53:19
问题 I am trying a rack middleware, to do authentication in a separate layer. The problem is, all request goes through this layer. I don't want the asset request like css, javascript to go through authentication middleware., I also don't want logout flow to go through this., In application.rb config.middleware.use AuthClient::MyFilterClass I am expecting something like config.middleware.use AuthClient::MyFilterClass, :exclude => [:logout,'*/assets/*'] Is there any way to exclude custom path /

How do I configure WEBrick to use an intermediate certificate with HTTPS?

ぐ巨炮叔叔 提交于 2019-12-19 05:34:11
问题 I am currently using the following options in my Rails app to enable HTTPS with WEBrick: { :Port => 3000, :environment => (ENV['RAILS_ENV'] || "development").dup, :daemonize => false, :debugger => false, :pid => File.expand_path("tmp/pids/server.pid"), :config => File.expand_path("config.ru"), :SSLEnable => true, :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE, :SSLPrivateKey => OpenSSL::PKey::RSA.new( File.open("certificates/https/key.pem").read), :SSLCertificate => OpenSSL::X509::Certificate

Rails 4.2 server; private and public ip not working

微笑、不失礼 提交于 2019-12-18 19:24:48
问题 I recently updated my rails 4.1.8 to 4.2 I'm not able to access rails app using private ip 192.168.1.x:3000 and also with my public-ip address . Rails app is working with lvh.me:3000 , 0.0.0.0:3000 , localhost:3000 and 127.0.0.1:3000 . But it looks all the the address are pointing to 127.0.0.1:3000 in my server log rails-issue. It was working fine in 4.1 I tried adding following in environments/development.rb , but nothing changed. TRUSTED_PROXIES = %r{ ^127\.0\.0\.1$ | # localhost ^(10 | #

How to test Sinatra app using session

空扰寡人 提交于 2019-12-18 17:13:43
问题 How to test Sinatra application wich is using session? get "/", {}, {'rack.session' => { 'foo' => 'blah' } } This code doesn't work for me, I have 'enable :sessions' in my app. 回答1: It looks like the problem is actually to have enable :sessions activated. You have to deactivate this setting in order to be available to overwrite the session . The solution could be: # my_test.rb (first line, or at least before you require your 'my_app.rb') ENV['RACK_ENV'] = 'test' # my_app.rb (your sinatra

How to test Sinatra app using session

我是研究僧i 提交于 2019-12-18 17:13:28
问题 How to test Sinatra application wich is using session? get "/", {}, {'rack.session' => { 'foo' => 'blah' } } This code doesn't work for me, I have 'enable :sessions' in my app. 回答1: It looks like the problem is actually to have enable :sessions activated. You have to deactivate this setting in order to be available to overwrite the session . The solution could be: # my_test.rb (first line, or at least before you require your 'my_app.rb') ENV['RACK_ENV'] = 'test' # my_app.rb (your sinatra

What is the “env” variable in Rack middleware?

寵の児 提交于 2019-12-18 14:04:45
问题 I know a Rack middleware filter is a Ruby class with an initialize and a call method. I know the call method takes an "env" argument. Something like this: class MyFilter def initialize(app) end def call(env) end end My question is: what exactly is the "env" argument sent to "call"? Is this the same as the Rails ENV environment (ie. development, testing, production). Thanks! 回答1: env is just a hash. Rack itself and various middlewares add values into it. To understand what the various keys are