cli icon indicating copy to clipboard operation
cli copied to clipboard

Make bind address configurable for app dev server

Open lmcrean opened this issue 3 months ago • 3 comments

Adds configurable bind address support to the shopify app dev command to enable Docker container development workflows.

Problem

  • Fixes #6355
  • Recent CLI versions hardcode localhost binding for app dev servers for security
  • Docker containers require 0.0.0.0 binding to accept connections from host machine
  • Theme dev server already supports --host flag, but app dev server does not
  • Breaks containerized development setups (working version was 3.83.3)

Solution

  • Add --host flag to shopify app dev command with SHOPIFY_FLAG_HOST env 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 --host flag 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.0 for 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.0 enables external connections
  • [x] Verify SHOPIFY_FLAG_HOST environment 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.

lmcrean avatar Sep 14 '25 07:09 lmcrean

any eta when this will be looked at? It's blocking me working on an app that uses docker

theo-styles-radiant avatar Oct 15 '25 13:10 theo-styles-radiant

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.

github-actions[bot] avatar Nov 15 '25 03:11 github-actions[bot]

can someone review this PR please?

lmcrean avatar Nov 15 '25 10:11 lmcrean

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

lmcrean avatar Nov 26 '25 13:11 lmcrean