Skip to content

Add separate frontend and backend port configuration for demo command#7

Merged
robdimarco-atxp merged 3 commits intomainfrom
robdimarco/atxp-243-allow-users-to-specify-what-port-and-working-directory-to
Sep 9, 2025
Merged

Add separate frontend and backend port configuration for demo command#7
robdimarco-atxp merged 3 commits intomainfrom
robdimarco/atxp-243-allow-users-to-specify-what-port-and-working-directory-to

Conversation

@robdimarco-atxp
Copy link
Contributor

Summary

Implements ATXP-243: Add separate --frontend-port and --backend-port options to replace the single --port option, giving users granular control over both frontend and backend ports when running the demo.

Key Features

Separate port control: --frontend-port (default: 3000) and --backend-port (default: 3001)
Automatic .env generation: Creates appropriate .env files for frontend and backend directories
Seamless integration: Works with existing atxp-express-example port configuration system
Graceful fallbacks: Uses environment variables if .env creation fails
Updated documentation: Comprehensive help text and usage examples

Changes Made

🔧 Command Line Interface

  • Replace --port, -p with --frontend-port, --fp and --backend-port, --bp
  • Short flags: --fp for frontend port, --bp for backend port
  • Default ports align with atxp-express-example: frontend 3000, backend 3001

📁 Configuration Management

  • Backend .env: PORT=${backendPort} and FRONTEND_PORT=${frontendPort} (for CORS)
  • Frontend .env: PORT=${frontendPort} and REACT_APP_BACKEND_PORT=${backendPort} (for proxy)
  • Automatic creation in respective directories during demo startup
  • Warning message with fallback if .env creation fails

📚 Documentation Updates

  • Updated help text with new port options and clear examples
  • Comprehensive usage examples showing port combinations
  • Updated default port information throughout

Integration with atxp-express-example

This implementation leverages the port configuration system added in atxp-express-example PR #6:

  • Backend uses PORT and FRONTEND_PORT environment variables
  • Frontend's configure-proxy.js script reads REACT_APP_BACKEND_PORT
  • Seamless proxy configuration for API calls

Usage Examples

# Default ports (frontend: 3000, backend: 3001)
npx atxp demo

# Custom frontend port
npx atxp demo --frontend-port 4000

# Custom backend port  
npx atxp demo --backend-port 4001

# Both custom ports
npx atxp demo --frontend-port 4000 --backend-port 4001

# With other options
npx atxp demo --frontend-port 4000 --backend-port 4001 --verbose --dir ./my-demo

Test Plan

  • Help command shows new port options correctly
  • Default ports work (frontend: 3000, backend: 3001)
  • Custom port parsing works for both frontend and backend
  • .env files created with correct content in both directories
  • Demo starts successfully with custom ports
  • Frontend proxy configures correctly to backend port
  • Browser opens to correct frontend port
  • Graceful fallback when .env creation fails
  • Verbose logging shows .env creation process

Files Changed

  • src/index.ts - Updated argument parsing and DemoOptions interface
  • src/help.ts - Updated help documentation and examples
  • src/run-demo.ts - Added .env file generation and updated startDemo function

🤖 Generated with Claude Code

Implement ATXP-243: Allow users to specify separate frontend and backend ports
when running the demo, replacing the single --port option with more granular control.

## Changes Made

### Command Line Interface
- Replace `--port, -p` with `--frontend-port, --fp` and `--backend-port, --bp`
- Update default ports: frontend 3000, backend 3001 (matching atxp-express-example defaults)
- Maintain backward compatibility by using sensible defaults

### Configuration Management
- Generate .env files for both frontend and backend directories with appropriate port settings
- Backend .env: `PORT` and `FRONTEND_PORT` (for CORS configuration)
- Frontend .env: `PORT` and `REACT_APP_BACKEND_PORT` (for proxy configuration)
- Graceful fallback if .env creation fails (uses environment variables)

### Updated Documentation
- Comprehensive help text with new port options and examples
- Clear usage examples showing frontend/backend port combinations
- Updated default port information throughout

## Implementation Details

The demo command now:
1. Parses separate frontend/backend port arguments
2. Creates appropriate .env files in the cloned repository
3. Passes environment variables to the demo process
4. Uses frontend port for browser opening and user messaging

This integrates seamlessly with the atxp-express-example repository's existing
port configuration system implemented in PR #6.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@linear
Copy link

linear bot commented Sep 9, 2025

- Frontend port: 8016 (original default, maintains backward compatibility)
- Backend port: 8017 (one number higher as requested)
- Updated help documentation with new default port values
- Verified .env file generation works correctly with new defaults

This preserves existing user expectations while providing the requested
port separation functionality.
Remove global PORT environment variable that was overriding backend .env file.
Now each service (frontend/backend) reads its PORT from its own .env file,
allowing them to run on separate ports correctly.

Fixes issue where backend was running on frontend port instead of backend port,
causing ECONNREFUSED errors in the proxy connection.

Verified fix: Backend=8017, Frontend=8016, proxy connections working.
@robdimarco-atxp robdimarco-atxp merged commit 16d22a3 into main Sep 9, 2025
1 check passed
@robdimarco-atxp robdimarco-atxp deleted the robdimarco/atxp-243-allow-users-to-specify-what-port-and-working-directory-to branch September 9, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant