rack

How to setup URLs for static site with Ruby Rack on Heroku

╄→尐↘猪︶ㄣ 提交于 2019-11-29 02:49:00
问题 My site is here. It used to be a Django-powered blog. However I no longer update it so I just wanted to make it a static HTML site. I wget'ed it and moved it to Heroku with Ruby Rack. However every URL resolves to the home page. This is because of my config.ru file: use Rack::Static, :urls => ["/media/images", "/media/js", "/media/css"], :root => "public" run lambda { |env| [ 200, { 'Content-Type' => 'text/html', 'Cache-Control' => 'public, max-age=86400' }, File.open('public/index.html',

Disable Sprockets asset caching in development

喜你入骨 提交于 2019-11-29 01:25:21
I'm using Rails 3.2.13 and the Rails Asset Pipeline. I want to use the Asset Pipeline so I can use SASS and CoffeeScript and ERB for my assets and have the Pipeline automatically compile them, so I cannot turn off the pipeline in development. I am not precompiling assets in development ever and there is not even a public/assets/ directory. However, when I make changes to an included file, such as to a _partial.html.erb file that is included (rendered) in a layout.html.erb file, without changing the file doing the including itself (in this example layout.html.erb ), Sprockets doesn't detect the

How do I set/get session vars in a Rack app?

谁说胖子不能爱 提交于 2019-11-29 01:17:17
use Rack::Session::Pool ... session[:msg]="Hello Rack" EDIT: The word session doesn't seem to resolve. I included the Session pool middleware in my config.ru, and try to set a variable in an ERB file (I'm using Ruby Serve) and it complains "undefined local variable or method `session'" Thanks! session is a method that is part of some web frameworks, for example Sinatra and Rails both have session methods. Plain rack applications don’t have a session method, unless you add one yourself. The session hash is stored in the rack env hash under the key rack.session , so you can access it like this

mongoid query caching

混江龙づ霸主 提交于 2019-11-29 01:08:08
问题 Rails' ActiveRecord has a feature called Query Caching (ActiveRecord::QueryCache) which saves the result of SQL query for the life-span of a request. While I'm not very familiar with the internals of the implementation, I think that it saves the query results somewhere in the Rack env, which is discarded in the end of the request. The Mongoid, unfortunately, doesn't currently provide such feature, and this is exacerbated by the fact, that some queries occur implicitly (references). I'm

Rack::Request - how do I get all headers?

浪子不回头ぞ 提交于 2019-11-29 00:59:22
The title is pretty self-explanatory. Is there any way to get the headers (except for Rack::Request.env[] )? The HTTP headers are available in the Rack environment passed to your app: HTTP_ Variables: Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with HTTP_). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request. So the HTTP headers are prefixed with "HTTP_" and added to the hash. Here's a little program that extracts and displays them: require 'rack' app =

8、关于Coordinator

人盡茶涼 提交于 2019-11-29 00:50:40
参考链接: https://www.jianshu.com/p/f01f5f0309a9 一、旧版本Scala消费者客户端的缺陷 在kafka0.9及以前版本的consumer会在zookeeper上/consumers/groupId/ids、/consumers/groupId/topics、/consumers/groupId/owners下注册watch。一旦有变化,所有的consumer都得到通知,都进行rebanlace操作。 这种方式有几种缺陷: 1、zk压力很大 2、羊群效应,就是大量watch需要通知,可能会导致其他任务阻塞 3、脑裂效应,所有consumer都接收到通知,进行rebanlance,相互之间没法控制。 所以在kafka0.9版本引入了协调器Coordinator 二、协调器分类及功能 每个broker启动的时候都会创建一个GroupCoordinator,每个客户端都有一个ConsumerCoordinator协调器。 ConsumerCoordinator每间隔3S中就会和GroupCoordinator保持心跳,如果超时没有发送,并且再过Zookeeper.time.out = 10S中则会触发rebanlance 1、GroupCoordinator 1、接受ConsumerCoordinator的JoinGroupRequest请求 2

Using Cookies with Rack::Test

亡梦爱人 提交于 2019-11-28 23:31:42
I'm trying to write RSpec tests for my Sinatra application using Rack::Test. I can't understand how I can use cookies. For example if my application set cookies (not via :session) how can I check whether that cookie is properly set? Also, how can I send requests with that cookie? Rack::Test keeps a cookie jar that persists over requests. You can access it with rack_mock_session.cookies . Let's say you have a handler like this: get '/cookie/set' do response.set_cookie "foo", :value => "bar" end Now you could test it with something like this: it 'defines a cookie' do get '/' rack_mock_session

How do I specify Origin Whitelist Options in Sinatra using Rack/Protection

我怕爱的太早我们不能终老 提交于 2019-11-28 21:22:20
问题 I have a web app, lets say http://web.example.com making a POST request to http://api.example.com. The api server is running the latest version of Sinatra with rack protection enabled. I am getting this error 'attack prevented by Rack::Protection::HttpOrigin'. I can do something like this: set :protection, :except => [:http_origin] but I feel like I am just ignoring the actual problem. I have tried to do this: use Rack::Protection::HttpOrigin, :origin_whitelist => ['http://web.example.com']

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

Rails 3.1 Force Regular HTTP

半城伤御伤魂 提交于 2019-11-28 20:43:17
Previously, I had been using ssl_requirement to give us fine grained control over which pages were served over ssl and which were served over plain http. According to the ssl_requirement's own wiki, it has been superseded by rails 3.1's Force SSL . However this does not seem to be the case. Force SSL doesn't seem to expose an option to go in the opposite direction, there is no way to force a page to sent via regular http. What is the correct Rails 3.1 way to force a page to be displayed in plain http? Does Force SSL truly supersede ssl_requirement? The code for Force SSL is pretty easy to read