rack

sync rack request and response

我的未来我决定 提交于 2019-12-13 21:26:44
问题 In my rails 4 app I'd like to response with html both for html and js request. At the moment when the request is html type the rendering works fine, but when the request is js then the html file doesn't get rendered on the screen (although in the command line it says it's rendered). There are different scenarios for limiting requests so the throttle code can be triggered by html POST and js POST request as well. Rack::Attack.throttle(key, limit: from_config(key, :limit), period: from_config

Serve HTML files stored on S3 on a Rack app

痴心易碎 提交于 2019-12-13 19:04:09
问题 Say I have some HTML documents stored on S3 likes this: http://alan.aws-s3-bla-bla.com/posts/1.html http://alan.aws-s3-bla-bla.com/posts/2.html http://alan.aws-s3-bla-bla.com/posts/3.html http://alan.aws-s3-bla-bla.com/posts/1/comments/1.html http://alan.aws-s3-bla-bla.com/posts/1/comments/2.html http://alan.aws-s3-bla-bla.com/posts/1/comments/3.html etc, etc I'd like to serve these with a Rack (preferably Sinatra) application, mapping the following routes: get "/posts/:id" do render "http:/

How to specify memcache server to Rack::Session::Memcache?

主宰稳场 提交于 2019-12-13 16:32:22
问题 I'm trying to configure my Rack app to use Memcache for sessions with Rack::Session::Memcache How do I give it the options (such as server, username and password)? Presently I have use Rack::Session::Memcache But I get the error in `initialize': No memcache servers (RuntimeError) Heroku has put the config in environment variables MEMCACHE_PASSWORD: MEMCACHE_SERVERS: MEMCACHE_USERNAME: I know I can get these in Ruby with ENV['MEMCACHE_PASSWORD'] but I don't know how to give them to Rack:

Sinatra rack middleware hijacks '/' root url

只愿长相守 提交于 2019-12-13 12:22:51
问题 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

How to ship a Sinatra application as a gem and deploy it?

痴心易碎 提交于 2019-12-13 11:50:28
问题 I have a sinatra application and packaged that as a gem. Its file-layout looks roughly like this: ├── bin │ └── tubemp ├── lib │ └── tubemp.rb ├── Gemfile └── tubemp.gemspec I can install and run it just fine. Calling ruby lib/tubemp.rb fires the app too, because Sinatra made it self-starting. tubemp.rb : class Tubemp < Sinatra::Application get '/' do erb :index, :locals => { :title => "YouTube embeds without third party trackers." } end end The binary is really simple too. bin/tubemp : #!

Building Rack Middleware responses with Flash message functionality

房东的猫 提交于 2019-12-13 02:24:46
问题 I have a Sinatra app that's mounted on a Rails app under /admin . The Sinatra app is an admin dashboard, and therefore should only be available to authorized users. To enforce that, I built a piece of Rack Middleware that will run before the Sinatra app is called. The logic is simple - If user is authenticated, continue as normal If user is not authenticated, redirect to the root path with a flash alert message (I'm using the rack-flash gem to allow access to the flash messages in Rack) Code

What is the exact difference between Rack and Rails Metal in Ruby on Rails

送分小仙女□ 提交于 2019-12-13 00:48:25
问题 I am newbie to Rack and Rails metal, can anyone tell me which situation has to use which?. According to my understanding both Rack and Metal to filter/bypass http request and response. Need a better clarification, when to use what? Thanks in advance!!! 回答1: As far as I know Rails Metal has been removed from Rails 3 a long time ago. Basically it used to be a thin wrapper around Rack that could act more like an endpoint rather than a filter (which is usually the case with Rack middleware).

Rails 3.2, handle corrupted request bodies (MultiJson::DecodeError)

拥有回忆 提交于 2019-12-12 13:16:27
问题 I'm working on a Rails 3.2.11 application (MRI 1.9.3). PArt of it is a webservice that receives POST requests with JSON serialized bodies. Everything works, but I want it to be resilient to bad formatted requests, e.g. invalid JSON. Right now, if it receives a JSON with – let's say – a missing comma, it will return a 500 error with an HTML response containing the default rails error view (plus the backtrace when in dev). I want to customize it to return a JSON or XML response with info about

Reloading rails middleware without restarting the server in development

馋奶兔 提交于 2019-12-12 09:35:53
问题 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

Rack Error with DreamHost, Passenger, and Rails 3.0.0.rc

℡╲_俬逩灬. 提交于 2019-12-12 08:54:42
问题 Background: I have viewed this question as well as this one - sadly, to no avail. Error Message (Passenger): You have already activated rack 1.1.0, but your Gemfile requires rack 1.2.1. Consider using bundle exec. my Gemfile: source 'http://rubygems.org' gem 'rails', '3.0.0.rc' gem 'nifty-generators' gem 'nokogiri' group :after_initialize do gem 'feedzirra' end my Gemfile.lock has this line: rack (1.2.1) my environment.rb has this line at the top: ENV['GEM_PATH'] = File.expand_path('~/.gems')