Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3ebe213
fix: use ${PORT:-3000} in Procfile.dev template to avoid worktree por…
ihabadham Mar 5, 2026
7ce155b
fix: use ${PORT:-N} in Procfile variant templates
ihabadham Mar 5, 2026
5026b83
feat: add .env.example template for per-worktree port configuration
ihabadham Mar 5, 2026
e717cb8
feat: copy .env.example during generator install
ihabadham Mar 5, 2026
85abb9c
test: assert env-var ports and .env.example in base generator output
ihabadham Mar 5, 2026
60573e7
docs: document worktree port configuration with .env pattern
ihabadham Mar 5, 2026
f84641a
feat: add PortSelector for automatic free port detection
ihabadham Mar 5, 2026
bcc9a59
feat: wire PortSelector into ServerManager before process manager starts
ihabadham Mar 5, 2026
f98bd7e
docs: update worktree section — auto port detection is now zero-config
ihabadham Mar 5, 2026
71c8bd3
test: fill coverage gaps in PortSelector and procfile_port
ihabadham Mar 5, 2026
ad62225
test(generator): assert Procfile.dev-prod-assets uses env-var-driven …
ihabadham Mar 5, 2026
fd4806f
docs(generator): clarify PORT default differs between Procfile variants
ihabadham Mar 5, 2026
d09b9d8
docs(process-managers): fix stale process names in Procfile.dev snippet
ihabadham Mar 5, 2026
0bc50cd
docs(process-managers): warn direct foreman users about PORT injection
ihabadham Mar 5, 2026
47d1844
fix(server_manager): configure ports before printing the access URL b…
ihabadham Mar 5, 2026
d67ace7
refactor(port_selector): remove unused WEBPACK_OFFSET and deduplicate…
ihabadham Mar 5, 2026
f4eca17
docs(process-managers): add language tag to fenced code block (MD040)
ihabadham Mar 5, 2026
ee004b6
fix(server_manager): rescue NoPortAvailable in configure_ports for cl…
ihabadham Mar 5, 2026
5dd07fd
test(server_manager): restore ENV vars instead of deleting in port co…
ihabadham Mar 5, 2026
446ce06
docs(port_selector): document TOCTOU limitation in port_available?
ihabadham Mar 5, 2026
9ecb4be
fix(generator): add .env to .gitignore so port config is not accident…
ihabadham Mar 5, 2026
d120d53
test(server_manager): clear ENV before each example to prevent order-…
ihabadham Mar 5, 2026
f06b6ff
fix(port_selector): probe the unset side in single-ENV branches
ihabadham Mar 5, 2026
3305a64
fix(server_manager): pass auto-detected port to print_server_info in …
ihabadham Mar 5, 2026
bfec470
fix: probe Rails and webpack ports independently in find_free_pair
ihabadham Mar 5, 2026
5fe353a
fix(server_manager): use procfile_port in run_production_like banner
ihabadham Mar 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/building-features/process-managers.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,35 @@ Edit `Procfile.dev` in your project root to customize which processes run and th
The default `Procfile.dev` includes:

```procfile
rails: bundle exec rails s -p 3000
rails: bundle exec rails s -p ${PORT:-3000}
wp-client: bin/shakapacker-dev-server
wp-server: SERVER_BUNDLE_ONLY=true bin/shakapacker --watch
```

## Running Multiple Worktrees Simultaneously

If you use [git worktrees](https://git-scm.com/docs/git-worktree) to work on multiple branches in parallel, each worktree's `bin/dev` will conflict on the default ports (3000 for Rails, 3035 for webpack-dev-server).

Create a `.env` file in each worktree (gitignored by default in Rails apps). Both foreman and overmind read `.env` automatically on startup.

The generated `Procfile.dev` uses `${PORT:-3000}`, so setting `PORT` is enough for Rails. For the webpack dev server, Shakapacker reads `SHAKAPACKER_DEV_SERVER_PORT` natively on both the Ruby proxy and the webpack-dev-server JS sides — no `shakapacker.yml` changes needed.

**Worktree 1** — use defaults (no `.env` needed), or set explicitly:

```sh
PORT=3000
SHAKAPACKER_DEV_SERVER_PORT=3035
```

**Worktree 2 `.env`:**

```sh
PORT=3001
SHAKAPACKER_DEV_SERVER_PORT=3036
```

A `.env.example` is generated by `rails g react_on_rails:install` as a starting point. Copy it to `.env` and adjust ports as needed.

## See Also

- [HMR and Hot Reloading](./hmr-and-hot-reloading-with-the-webpack-dev-server.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def copy_base_files
Procfile.dev-static-assets
Procfile.dev-prod-assets
.dev-services.yml.example
.env.example
bin/shakapacker-precompile-hook]

# HelloServer uses the hello_world layout so React on Rails can inject generated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Development environment configuration
# Copy this file to .env to override default ports.
#
# This is especially useful when running multiple git worktrees simultaneously.
# Each worktree needs its own .env with different ports to avoid conflicts.
#
# Shakapacker reads SHAKAPACKER_DEV_SERVER_PORT on both the Ruby (proxy) and
# JS (webpack-dev-server) sides, so no shakapacker.yml changes are needed.
#
# Example for a second worktree:
# PORT=3001
# SHAKAPACKER_DEV_SERVER_PORT=3036

# Rails server port (default: 3000, used by Procfile.dev)
# PORT=3000

# Webpack dev server port (default: 3035, used by shakapacker)
# SHAKAPACKER_DEV_SERVER_PORT=3035
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Procfile for development
# You can run these commands in separate shells
rails: bundle exec rails s -p 3000
#
# To run multiple worktrees simultaneously, set different ports in each worktree's .env:
# PORT=3001
# SHAKAPACKER_DEV_SERVER_PORT=3036
rails: bundle exec rails s -p ${PORT:-3000}
dev-server: bin/shakapacker-dev-server
server-bundle: SERVER_BUNDLE_ONLY=yes bin/shakapacker --watch
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Uses production-optimized, precompiled assets with development environment
# Uncomment additional processes as needed for your app

rails: bundle exec rails s -p 3001
rails: bundle exec rails s -p ${PORT:-3001}
# sidekiq: bundle exec sidekiq -C config/sidekiq.yml
# redis: redis-server
# mailcatcher: mailcatcher --foreground
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: bin/rails server -p 3000
web: bin/rails server -p ${PORT:-3000}
js: bin/shakapacker --watch
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
config/initializers/react_on_rails.rb
Procfile.dev
Procfile.dev-static-assets
Procfile.dev-prod-assets].each { |file| assert_file(file) }
Procfile.dev-prod-assets
.env.example].each { |file| assert_file(file) }
end

it "uses env-var-driven port in Procfile.dev" do
assert_file "Procfile.dev", /\$\{PORT:-3000\}/
end

it "uses env-var-driven port in Procfile.dev-static-assets" do
assert_file "Procfile.dev-static-assets", /\$\{PORT:-3000\}/
end
end

Expand Down
Loading