Print proxy URL when starting Dev Proxy in detach mode#1591
Print proxy URL when starting Dev Proxy in detach mode#1591garrytrinder merged 9 commits intomainfrom
Conversation
…mode Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves detached-mode startup output so callers can discover the actual proxy address when using OS-assigned ports (--port 0), by persisting the resolved proxy port and printing a Proxy URL in the parent process.
Changes:
- Update
ProxyEngineto set the runtime port after the proxy endpoint is started, and (when running as the internal daemon) re-save the detached state file with the resolved port. - Update detached-mode startup polling to wait for
state.Port > 0and print a newProxy URL:line in the console output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| DevProxy/Proxy/ProxyEngine.cs | After starting the proxy endpoint, updates the effective port and re-saves detached state with the resolved port for --port 0. |
| DevProxy/Program.cs | In detached startup output, waits for a non-zero port and prints the resolved Proxy URL alongside PID/API URL/log file. |
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
garrytrinder
left a comment
There was a problem hiding this comment.
Bug: API URL shows port 0 when using --api-port 0
While the proxy port resolution works correctly (the main goal of this PR), the same issue exists for the API port when --api-port 0 is used.
Steps to reproduce
devproxy --detach --as-system-proxy false --port 0 --api-port 0Expected output
Dev Proxy started in background.
PID: 4588
Proxy URL: http://127.0.0.1:63860
API URL: http://127.0.0.1:64123
Actual output
Dev Proxy started in background.
PID: 4588
Proxy URL: http://127.0.0.1:63860
API URL: http://127.0.0.1:0
The API URL retains port 0 because ProxyInstanceState is saved in Program.cs before Kestrel binds to the actual port. The proxy port fix in ProxyEngine.ExecuteAsync updates _config.Port from _explicitEndPoint.Port after binding, but no equivalent resolution happens for the Kestrel API port.
Impact
devproxy stopfails withCan't assign requested address (127.0.0.1:0)— must use--forcedevproxy statusshows the wrong API URL- Any tooling relying on the JSON output to discover the API endpoint gets an unusable URL
Suggestion
Read the actual Kestrel-bound port from IServerAddressesFeature after startup and update the state file, similar to how the proxy port is resolved from _explicitEndPoint.Port. PR #1589 already does this for the API port via IServer injection in ProxyEngine — worth aligning with that approach.
Not a regression (this existed before this PR), but since this PR specifically improves the --port 0 experience, it would be good to handle the API port too for a complete fix.
|
With you're likely testing the globally installed version rather than the one built from PR. This caught me too. |
Resolve conflict in Program.cs: combine proxy URL computation from this branch with JSON output support from main. Both text and JSON output now include the Proxy URL.
|
Re-tested using the branch build ( dotnet run --project DevProxy -- --detach --as-system-proxy false --port 0 --api-port 0Output (branch build, confirmed by Proxy URL line which only exists on this branch):
Bug confirmed on branch build. |
After Kestrel binds, read the actual API address from IServerAddressesFeature and update the state file. The parent process now also waits for a resolved API URL before printing the detach output.
garrytrinder
left a comment
There was a problem hiding this comment.
Re-tested after the latest commits. All scenarios pass:
--port 0 --api-port 0: Both Proxy URL and API URL now resolve to real ports ✅--output json: Valid JSONL with correct proxyUrl and apiUrl ✅- Explicit ports (
--port 9080 --api-port 9081): Works correctly ✅ stopcommand: Works in all cases ✅
The API URL port 0 bug is fixed. Nice work.
|
@copilot resolve the merge conflicts |
…d-port-number # Conflicts: # DevProxy/Program.cs # DevProxy/Proxy/ProxyEngine.cs
SaveInstanceStateAsyncapproach + imports)LoadStateByPidAsyncfrom main, keep Proxy URL output and port-ready waiting)UpdateStateWithApiUrlAsyncin DevProxyCommand.cs to use per-PID state APIOriginal prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.