rack

Simple and Ideal Logging in Sinatra

那年仲夏 提交于 2019-12-03 16:18:46
I went through few blogs and sites which gave me some information about how to log in sinatra but didnt work for my app and also i went through a gem called sinatra-logger didnt tried it, wanted to know ideal and simple way to "log" in sinatra. Like we do logger.info for rails. The code which i tried and didnt work is from the following site link and also some of SO links were too pointing to the same approach used in the link above. configure do LOGGER = Logger.new("sinatra.log") end helpers do def logger LOGGER end end i have written this in app.rb of my app, it fails saying undefined method

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

耗尽温柔 提交于 2019-12-03 15:52:38
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 : #!/usr/bin/env ruby require "tubemp.rb" Tubemp.run! But now I want to deploy this as Rack-app. Or deploy it

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

Rails 3, HTTP extensions (WebDAV) and Rack App mounting

霸气de小男生 提交于 2019-12-03 13:28:48
1 The following is more to point out to the code devs an issue of rails that can be percieved as a flaw. 2 And also me asking some oppinions from people who know better. I want to add WebDAV to my Rails 3 App with Warden authentication. My warden middleware is injected via Devise. http://github.com/chrisroberts/dav4rack http://github.com/hassox/warden http://github.com/plataformatec/devise I cannot mount DAV4Rack handlers from inside rails app (routes), like this: # in config/routes.rb mount DAV4Rack::Handler.new( :root => Rails.root.to_s, # <= it's just an example :root_uri_path => '/webdav',

You have already activated rack 1.3.2, but your Gemfile requires rack 1.2.3. Consider using bundle exec

左心房为你撑大大i 提交于 2019-12-03 13:10:00
问题 I've got a problem while i try to run my app : You have already activated rack 1.3.2, but your Gemfile requires rack 1.2.3. Consider using bundle exec. I read a lot about this kind of error, but i did not find any solution that worked for me I already removed my Gemfile.lock and re-run bundle as suggested here I already use the latest version of passenger (3.0.8) - as suggested here The bundle exec rake trick cannot be used in my case Thank you per advance 回答1: Run bundle install --binstubs

Deleting the current session with Rack::Session::Cookie

与世无争的帅哥 提交于 2019-12-03 10:47:24
问题 I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-) enable :sessions get '/logout' do # What goes here to kill the session? end 回答1: Just use session.clear to destroy the session. 回答2: It depends how you create your session. Simply you have to nulify session entry. Here is simple example, how to create and destroy sessions. get '/login' do session[:username] = params[:username] "logged

Websocket header missing

僤鯓⒐⒋嵵緔 提交于 2019-12-03 08:50:40
问题 I'm using the 'faye' gem with Rails 3.2.13. In development I'm running faye on localhost:9292 and my app on localhost:3000. I'm able to activate pop-up windows with a curl request from the command line but I can't establish a connection from within my app. The error I'm getting in my console is: WebSocket connection to 'ws://localhost:9292/faye' failed: Error during WebSocket handshake: 'Upgrade' header is missing I am trying to define a header for faye in my application.js file: $(function()

Robust way to deploy a Rack application (Sinatra)

我与影子孤独终老i 提交于 2019-12-03 08:40:48
I'm looking for a robust way to deploy a Rack application (in this case a Sinatra app). Requests will take a little time (0.25-0.5 sec waiting on proxied HTTP requests) and there may be a decent amount of traffic. Should I go with a traditional mongrel cluster setup? Use HAProxy as a load balancer? nginx? rackup? What solutions have you used and what are the advantages? Nginx / Unicorn FTW! Nginx in front to serve static files and unicorn to handle Sinatra app. Benefits: Performance, good load balancing with unix socks and deploy/upgrade without any downtimes (you can upgrade Ruby/Nginx

Why does Foreman not output some things until I press Control-C?

隐身守侯 提交于 2019-12-03 08:27:49
问题 I just got into rails programming and it looks like there are two programs I can use to run my project locally: rackup and foreman. One difference I noticed is that foreman will not output some things that I would expect to see and I would see if I ran rackup instead, until I press ctrl+c to close the server. Then all those messages appear, as if they were being hidden. Is there a reason for this? How can I get foreman to be more verbose? 回答1: If you are not seeing any output from your

Requests got stuck in ActiveRecord::QueryCache middleware

南楼画角 提交于 2019-12-03 07:58:17
After deploying our Rails app (4.0.9, Ruby 2.1.2), we notice requests to our app get hang after a while , usually 1 day or so. Using the gem rack_timer , we're able to find out requests got stuck at ActiveRecord::QueryCache middleware. Rack Timer (incoming) -- ActiveRecord::QueryCache: 925626.7731189728 ms After removing it, our app seems to be back to normal. However, I understand the purpose of this middleware is to increase the performance, so removing is just a temporary solution. We're using mysql (5.1.67) with adapter mysql2 (0.3.13) Update: Right after I posted this question, the server