The only difference I've noted is that rails server
starts the server on port 3000, while rackup
starts the server on port 9292.
Are there any other differences?
Are there use cases for one instead of the other?
Rack provides 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.
config.ru is a Rack configuration file ( ru stands for "rackup"). Rack provides a minimal interface between web servers that support Ruby and Ruby frameworks. It's like a Ruby implementation of a CGI which offers a standard protocol for web servers to execute programs.
Rack is a modular interface between web servers and web applications developed in the Ruby programming language. With Rack, application programming interfaces (APIs) for web frameworks and middleware are wrapped into a single method call handling HTTP requests and responses.
Rack compliant code must have the following three characteristics: It must respond to call. The call method must accept a single argument - This argument is typically called env or environment , and it bundles all of the data about the request.
rails server
is the command for starting your server (usually WEBrick) and is in rails.
rackup
is a command that comes with the rack middle and uses the settings in your config.ru and starts a server based off of those. This is a standard (it will work for other frameworks and rack-based applications) and is usually used in production servers.
One difference of note is that if you start a server with rails s
then you will see the output in the terminal.
In my experience, in production, rackup
is used by phusion passenger so you wouldn't want rails s
in that situation.
As an aside, the port can be changed with both rails server
and rackup
using the -p flag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With