Questions tagged [rack]

Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.

Rack is a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

Useful Links

1617 questions
284
votes
9 answers

What is Rack middleware?

What is Rack middleware in Ruby? I couldn't find any good explanation for what they mean by "middleware".
chrisgoyal
  • 4,297
  • 4
  • 22
  • 27
87
votes
3 answers

What's the difference between request.remote_ip and request.ip in Rails?

As the title goes, you can get the client's ip with both methods. I wonder if there is any differences. Thank you. in the source code there goes "/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.3/lib/action _dispatch/http/request.rb" 257L,…
Minqi Pan
  • 2,722
  • 2
  • 22
  • 26
77
votes
9 answers

HTML5 video will not loop

I have a video as a background to a web page, and I am trying to get it to loop. Here is the code:
75
votes
4 answers

Foreman: Use different Procfile in development and production

I have a homemade Sinatra application for which I intend to use Heroku to host it. I use foreman and shotgun in development, with the following Procfile: web: shotgun config.ru -s thin -o 0.0.0.0 -p $PORT -E $RACK_ENV It works great with both…
Arnaud Leymet
  • 5,995
  • 4
  • 35
  • 51
62
votes
25 answers

git, Heroku: pre-receive hook declined

I am in the process of setting up a git repository and attempting to link it to Heroku. When I run the command git push heroku master I receive Counting objects: 7, done. Delta compression using up to 2 threads. Compressing objects: 100% (5/5),…
wuliwong
  • 4,238
  • 9
  • 41
  • 69
56
votes
4 answers

Logging in Sinatra?

I'm having trouble figuring out how to log messages with Sinatra. I'm not looking to log requests, but rather custom messages at certain points in my app. For example, when fetching a URL I would like to log "Fetching #{url}". Here's what I'd…
Kyle Fox
  • 3,133
  • 4
  • 23
  • 26
45
votes
5 answers

How to parse JSON request body in Sinatra just once and expose it to all routes?

I am writing an API and it receives a JSON payload as the request body. To get at it currently, I am doing something like this: post '/doSomething' do request.body.rewind request_payload = JSON.parse request.body.read #do something with…
lmirosevic
  • 15,787
  • 13
  • 70
  • 116
44
votes
7 answers

Where do you put your Rack middleware files and requires?

I'm in the process of refactoring some logic built into a Rails application into middleware, and one annoyance I've run into is a seeming lack of convention for where to put them. Currently I've settled on app/middleware but I could just as easily…
Adam Lassek
  • 35,156
  • 14
  • 91
  • 107
42
votes
8 answers

How to determine if Rails is running from CLI, console or as server?

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…
crishoj
  • 5,660
  • 4
  • 32
  • 31
41
votes
4 answers

How to serve static files via Rack?

I am currently developing a Rack-based application and want to redirect all file requests (e.g. filename.filetype) to a specified folder. Rack::Static only supports file requests for a special folder(e.g. "/media"). Do I have to write my own Rack…
brainfck
  • 9,286
  • 7
  • 28
  • 29
38
votes
2 answers

How do I access the Rack environment from within Rails?

I have a Rack application that looks like this: class Foo def initialize(app) @app = app end def call(env) env["hello"] = "world" @app.call(env) end end After hooking my Rack application into Rails, how do I get access to…
Michael Gundlach
  • 106,555
  • 11
  • 37
  • 41
37
votes
5 answers

Any success with Sinatra working together with EventMachine WebSockets?

I have been using Sinatra for sometime now and I would like to add some realtime features to my web-app by pushing the data via websockets. I have successfully used the gem 'em-websocket' on its own, but have not been able to write one ruby file…
Poul
  • 3,426
  • 5
  • 37
  • 43
36
votes
1 answer

Rack concurrency - rack.multithread, async.callback, or both?

I'm attempting to fully understand the options for concurrent request handling in Rack. I've used async_sinatra to build a long-polling app, and am now experimenting with bare-metal Rack using throw :async and/or Thin's --threaded flag. I am…
bioneuralnet
  • 5,283
  • 1
  • 24
  • 30
36
votes
3 answers

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

The title is pretty self-explanatory. Is there any way to get the headers (except for Rack::Request.env[])?
PJK
  • 2,082
  • 3
  • 17
  • 28
36
votes
7 answers

Is there an easy way to have pow serve https?

pow is great, but many things in my app assume https, and it would be a pain to go through them all and add "if not dev environment". Is it possible to have pow serve https?
John Bachir
  • 22,495
  • 29
  • 154
  • 227
1
2 3
99 100