mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
fix: ensure CLI port takes precedence over env PORT (#3025)
## Port Configuration Priority Fix
### Problem
The Mastra CLI's port configuration had conflicting priority between the
`--port` flag and environment variables, where the `--port` flag was
being ignored when `PORT` environment variable existed.
### Solution
Modified the port configuration priority in the `startServer` function
to:
1. Give CLI arguments (`--port`) the highest priority
2. Fall back to environment variables (`PORT`) if no CLI argument
3. Use default value (`4111`) as the lowest priority
Added a warning when the CLI port overrides an existing PORT environment
variable for better transparency.
### Changes
- Reordered environment variable assignment to ensure CLI port takes
precedence
- Added warning message when overriding environment PORT variable
- Added changeset for patch version bump
### Before
```typescript
env: {
PORT: port.toString() || '4111',
...Object.fromEntries(env), // Could override PORT
}
```
### After
```typescript
env: {
...Object.fromEntries(env),
PORT: port.toString() || process.env.PORT || '4111',
}
```
### Testing
- Verified CLI port takes precedence when both `--port` flag and `PORT`
env var are set
- Tested fallback to environment PORT when no CLI port is specified
- Validated default port (4111) is used when neither CLI nor env PORT is
set
Fixes #3024
This commit is contained in:
parent
beaf1c212e
commit
2f6a8b615f
2 changed files with 7 additions and 3 deletions
Loading…
Add table
Add a link
Reference in a new issue