gws expose
Manage expose sessions for services.
Usageโ
gws expose add <service> [worktree] [options]
gws expose remove <service> [worktree]
gws expose list [worktree] [options]
Output:
# Starting expose session
๐ Starting expose session for service: api
Worktree: feature-auth
Namespace: myapp-feature-auth
โจ Expose session started successfully!
Service: api
Local: localhost:54321
Remote: myapp-feature-auth:9229
๐ก Test connection: curl http://localhost:54321
๐ก View status: gws status
๐ก Stop expose: gws expose remove api
Note: This command can be run from anywhere using the
-p [project]option.
Argumentsโ
<action>- Action: add, remove, or list. Required.[service]- Name of the service to expose (required for add/remove)[worktree]- Worktree name (optional, defaults to current worktree)
Optionsโ
| Option | Description | Default |
|---|---|---|
-p, --project <name> | Project name | Auto-detected from current directory |
--local-port <port> | Local port to bind (auto-allocated if not specified) | Auto-allocated |
--remote-port <port> | Remote port in container (defaults to service.port) | Service port |
--json | Output as JSON (for list action) | false |
Examples:
# Expose api service (default worktree)
gws expose add api
# Expose api in feature-auth worktree
gws expose add api feature-auth
# Expose with specific local port
gws expose add api --local-port 8080
# Expose with specific remote port
gws expose add api --remote-port 9229
# List active expose sessions
gws expose list
# List for specific worktree
gws expose list feature-auth
# List as JSON
gws expose list --json
# Stop expose session
gws expose remove api
# Stop expose for specific worktree
gws expose remove api feature-auth
Typical Use Casesโ
Debug Node.js applicationโ
# 1. Expose debugger port
gws expose add api feature-auth --remote-port 9229
# Output shows allocated port (e.g., localhost:54321)
# 2. Attach VS Code debugger
# In VS Code launch.json:
# {
# "type": "node",
# "request": "attach",
# "name": "Attach to Remote",
# "address": "localhost",
# "port": 54321
# }
Connect to databaseโ
# Expose database port with specific local port
gws expose add database feature-auth --remote-port 5432 --local-port 5433
# Connect with psql
psql -h localhost -p 5433 -U postgres -d myapp
Access Redis CLIโ
# Expose Redis port
gws expose add redis feature-auth --remote-port 6379
# Connect with redis-cli (use allocated port from output)
redis-cli -h localhost -p <allocated-port>
Monitor application metricsโ
# Expose Prometheus metrics
gws expose add api feature-auth --remote-port 9090 --local-port 9090
# Access metrics
curl http://localhost:9090/metrics
Multirepo Behaviorโ
When running gws expose in a multirepo setup, the command targets a specific service within the shared namespace.
Project Structureโ
myapp/ # Parent directory
โโโ .worktrees/ # Shared worktrees folder (at parent level)
โ โโโ feature-auth/ # One folder per worktree name
โ โโโ api/ # Worktree for api repo
โ โ โโโ src/
โ โโโ app/ # Worktree for app repo
โ โโโ src/
โโโ api/ # Git repo 1
โ โโโ .git/
โ โโโ src/
โโโ app/ # Git repo 2
โโโ .git/
โโโ src/
Exposing Service in Main Workspaceโ
cd myapp
gws expose add api --remote-port 9229
Output:
๐ Starting expose session for service: api
Worktree: myapp
Namespace: myapp
โจ Expose session started successfully!
Service: api
Local: localhost:54321
Remote: myapp:9229
What happens:
- Finds the
apiservice pod in namespacemyapp - Creates port-forward from localhost:54321 to api container port 9229
- Expose session persists in the background
Exposing Service in Worktreeโ
cd myapp
gws expose add database feature-auth --remote-port 5432 --local-port 5433
Output:
๐ Starting expose session for service: database
Worktree: feature-auth
Namespace: myapp-feature-auth
โจ Expose session started successfully!
Service: database
Local: localhost:5433
Remote: myapp-feature-auth:5432
What happens:
- Finds the
databaseservice pod in namespacemyapp-feature-auth - Creates port-forward from localhost:5433 to database container port 5432
- You can now connect to the database at localhost:5433
Listing Active Exposesโ
gws expose list
Output:
๐ Active Expose Sessions (3):
Namespace: myapp
โ
api: localhost:54321 โ 9229
Status: running
Namespace: myapp-feature-auth
โ
api: localhost:54322 โ 9229
Status: running
โ
database: localhost:5433 โ 5432
Status: running
Key Points:
- All services from all repos are in the same namespace
- You can expose different services from different worktrees simultaneously
- Each expose session gets its own unique local port
- Use
gws expose listto see all active port-forwards - Expose sessions persist until you stop the worktree with
gws downor manually remove withgws expose remove
Understanding exposeโ
The expose command creates a port-forward from your local machine to a container. It:
- Identifies the pod for the service
- Establishes a port-forward tunnel
- Binds the local port to the container port
- Keeps the connection active in the background
The port-forward runs as a background process and persists until you stop the worktree with gws down or manually remove the expose session.
Port Conflictsโ
If you get a "port already in use" error:
- Choose a different local port with
--local-port - Stop the process using the port
- Use
gws downto clean up existing port-forwards
See Alsoโ
- gws exec - Execute commands in containers
- gws logs - View service logs
- gws status - Check service status