rack

How to use rack middleware with Rails3?

人盡茶涼 提交于 2019-12-06 11:04:32
问题 Hey guys, I'm trying to make the rack middleware NotFound to work with rails3 but I needed to make some changes to return some json, so I basically defined a new class : class NotFound def initialize(app, msg, content_type = "text/html") @app = app @content = msg @length = msg.size.to_s @content_type = content_type end def call(env) [404, {'Content-Type' => @content_type, 'Content-Length' => @length}, @content] end end I added this class above to "app/middleware/not_found.rb" and add this

Adaptive images for ruby based servers

假装没事ソ 提交于 2019-12-06 10:38:00
I'd like to deliver images to client based on the size of the user screen, as in If I have High resolution image, and the user want to view it on a mobile I don't want to send the full HD image, instead I'd like to send the image shrinked to the user's device dimension which will increase the loading speed on low bandwidth devices There is a solution for this here Adaptive Images detects your visitor's screen size and automatically creates, caches, and delivers device appropriate re-scaled versions of your web page's embeded HTML images.It is intended for use with Responsive Designs and to be

Rack Web Server and https: tutorial?

纵饮孤独 提交于 2019-12-06 10:15:07
问题 Can anyone provide a link to a description or tutorial dealing with the setup of https and installint certs etc using the Ruby RACK webserver? Thanks 回答1: Rack isn't a webserver, it's an interface between webservers (like Apache, nginx) and applications middleware. If you're wanting to deploy a Rails application behind SSL, it's as easy as setting up SSL in your web server software. There are special things you can do in your app (such as forcing login pages to always use SSL), but they're

Are Rack-based web servers represent FastCGI protocol?

浪子不回头ぞ 提交于 2019-12-06 08:37:08
问题 I've read that CGI/FastCGI is a protocol for interfacing external applications to web servers. so the web server (like Apache or NginX) sends environment information and the page request itself to a FastCGI process over a socket and responses are returned by FastCGI to the web server over the same connection, and the web server subsequently delivers that response to the end-user. Now I'm confused between this and Rack, which is used by almost all Ruby web frameworks and libraries. It provides

Force 'www' in Rails3 hosted on Heroku without .htaccess

筅森魡賤 提交于 2019-12-06 06:52:52
问题 I was wondering if there was a Rack alternative to forcing the 'www' in the URL since Heroku doesn't use .htaccess files. Maybe even a nice way to do it in routes? Thanks 回答1: A quick Google search reveals this Rack middleware, which appears to do exactly what you want. 回答2: In your ApplicationController, you can simply create a before filter: before_filter :force_www! protected def force_www! if Rails.env.production? and request.host[0..3] != "www." redirect_to "#{request.protocol}www.#

How do I log asynchronous thin+sinatra+rack requests?

十年热恋 提交于 2019-12-06 05:47:51
问题 I'm writing my first Sinatra-based web app as a frontend to another TCP-based service, using EventMachine and async_sinatra to process incoming HTTP requests asynchronously. When I'm testing my app, all requests to synchronous routes are logged to stdout in common log format, but asynchronous requests are not. I've read through bits of the source code to async_sinatra, Sinatra, Thin, and Rack, and it looks like logging of synchronous requests is done through CommonLogger#call. However, I can

Update middleware in Rails

前提是你 提交于 2019-12-06 05:23:41
问题 Is there any way to MODIFY ( NOT replace) a middleware in rails? So instead of: config.middleware.delete ::Rack::Cache config.middleware.use ::Rack::Cache, :metastore => "rails:/", :entitystore => "rails:/", :verbose => false I want to simply write something like config.middleware.find!(::Rack::Cache).verbose = false . UPDATE: The reason to do it is because the capybara-webkit prints tons of messages when running from cucumber. 回答1: I think for this particular middleware, you can set the Rack

Heroku 301 Redirect

送分小仙女□ 提交于 2019-12-06 05:09:01
问题 How do I make it so http://domain.com 301 redirects to http://www.domain.com? I'm used to using .htaccess to ModRewrite it, but I've learned I can't do that on Heroku. Example of .htaccess: Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L] My file structure: - /public --- /style --- index.html - config.ru I'm just serving up the single page, and my config.ru consists of this: use Rack::Static, :urls => ["

Accessing session in Sinatra Middleware

≯℡__Kan透↙ 提交于 2019-12-06 04:21:51
问题 I am working on a Sinatra Project and have set some variables in the session for later usage. The scenario for which I need help for is that I want to access the session object in a middleware class. I am using warden for authentication. I want to do something similar below in the Middleware class: class MyMiddleware def initialize(app, options={}) @app = app end def call(env) puts "#{session.inspect}" end end Is there a possibility for doing that? Thoughts? 回答1: You can't use Sinatra's

no such file to load — rack

喜夏-厌秋 提交于 2019-12-06 03:21:02
问题 Sometimes, my rails application gives an error (no such file to load -- rack) even if rack is installed. [Gemfile] gem 'rack', '1.2.1' If I refresh the page, it loads fine. So it's not the gem problem. What could cause the error? Thanks. Sam 回答1: I think if you start your website locally, this will not happen. So what service did you use? I've encountered this kind of bugs on DreamHost. For DreamHost, the problem is they use different version (older) of Rack, which is not compatible with