mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Set The Default Development Port as a Rails til
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
|
||||
|
||||
_1051 TILs and counting..._
|
||||
_1052 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -687,6 +687,7 @@ _1051 TILs and counting..._
|
||||
- [Set A Timestamp Field To The Current Time](rails/set-a-timestamp-field-to-the-current-time.md)
|
||||
- [Set default_url_options For Entire Application](rails/set-default-url-options-for-entire-application.md)
|
||||
- [Set Schema Search Path](rails/set-schema-search-path.md)
|
||||
- [Set The Default Development Port](rails/set-the-default-development-port.md)
|
||||
- [Show Pending Migrations](rails/show-pending-migrations.md)
|
||||
- [Show Rails Models With Pry](rails/show-rails-models-with-pry.md)
|
||||
- [Show Rails Routes With Pry](rails/show-rails-routes-with-pry.md)
|
||||
|
||||
36
rails/set-the-default-development-port.md
Normal file
36
rails/set-the-default-development-port.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# Set The Default Development Port
|
||||
|
||||
For Rails 5+, Puma has been the default web server that gets installed with new
|
||||
Rails apps. Puma comes with some configuration in the `config/puma.rb` file.
|
||||
|
||||
If you open that file up, you'll see a number of settings that can be
|
||||
configured. One of them is the `port` that `puma` uses.
|
||||
|
||||
```ruby
|
||||
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
||||
#
|
||||
port ENV.fetch('PORT') { 3000 }
|
||||
```
|
||||
|
||||
It looks for a `PORT` value in the envionrment and uses that if it is present.
|
||||
That means you could run:
|
||||
|
||||
```bash
|
||||
PORT=5005 rails s
|
||||
```
|
||||
|
||||
and Puma would server the local development server at `localhost:5005`. If that
|
||||
value is not present, it will fallback to `#fetch`'s block which contains
|
||||
`3000`.
|
||||
|
||||
If you always want to local Rails development server to run at a port other
|
||||
than `3000`, all you need to do is update that line.
|
||||
|
||||
```ruby
|
||||
port ENV.fetch('PORT') { 5005 }
|
||||
```
|
||||
|
||||
Now, running `rails s` on its own will start the dev server up at
|
||||
`localhost:5005`.
|
||||
|
||||
[source](https://schneems.com/2017/03/13/puma-ports-and-polish/)
|
||||
Reference in New Issue
Block a user