Make bind address configurable for app dev server
Adds configurable bind address support to the shopify app dev command to enable Docker container development workflows.
Problem
- Fixes #6355
- Recent CLI versions hardcode
localhostbinding for app dev servers for security - Docker containers require
0.0.0.0binding to accept connections from host machine - Theme dev server already supports
--hostflag, but app dev server does not - Breaks containerized development setups (working version was 3.83.3)
Solution
- Add
--hostflag toshopify app devcommand withSHOPIFY_FLAG_HOSTenv var support - Update proxy server setup to use configurable host instead of hardcoded
'localhost' - Maintain secure default (
localhost) while enabling Docker flexibility - Match existing theme dev server pattern for consistency
Changes Made
1. Added host flag to app dev command
- File:
packages/app/src/cli/commands/app/dev.ts - Added
--hostflag with environment variable support - Default:
localhost(maintains security) - Override:
0.0.0.0(enables Docker containers)
2. Updated proxy server to use configurable host
- File:
packages/app/src/cli/services/dev/processes/setup-dev-processes.ts - Changed hardcoded
'localhost'to use passed host parameter - Added host parameter to proxy server setup function
Usage Examples
For Docker containers:
SHOPIFY_FLAG_HOST=0.0.0.0 shopify app dev
# or
shopify app dev --host=0.0.0.0
For normal development (default):
shopify app dev # Still binds to localhost by default
Testing
Unit Tests
Added comprehensive unit test coverage in packages/app/src/cli/services/dev/processes/setup-dev-processes.test.ts:
New Test: proxy server process includes host parameter when configured for Docker
- Purpose: Verifies that the proxy server correctly uses the host parameter when set to
0.0.0.0for Docker compatibility - Test setup: Creates a dev configuration with
host: '0.0.0.0'simulating Docker usage - Verification: Confirms the proxy server process options include the correct host value
- Location: Lines 85-150 in the test file
Updated Existing Tests
All existing tests were updated to include the required host: 'localhost' parameter in commandOptions to satisfy TypeScripts' requirements for the Devoptions interface. Users get localhost by default so no action needed.
Test Commands
# Run unit tests for the setup-dev-processes module
pnpm test packages/app/src/cli/services/dev/processes/setup-dev-processes.test.ts
Manual Testing
- [x] Verify default behavior unchanged (binds to localhost)
- [x] Verify
--host=0.0.0.0enables external connections - [x] Verify
SHOPIFY_FLAG_HOSTenvironment variable works - [x] Test Docker container setup with port forwarding
- [x] Ensure backwards compatibility
No Breaking Changes
This is a feature addition that maintains 100% backward compatibility. Users who don't need Docker support will see zero changes in behavior. Only users who specifically want to bind to a different network interface need to use the new --host flag.
any eta when this will be looked at? It's blocking me working on an app that uses docker
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.
can someone review this PR please?
Thank you for the professional notes @karreiro @isaacroldan
Just confirming that this is in my pipeline, it appears to be nearly there, I'll be engaging with it during end of December/ early Jan