Fix fwreinit failing to find server when web.webroot is set in server.json#41
Conversation
Agent-Logs-Url: https://github.com/ColdBox/coldbox-cli/sessions/23d22b0d-2e9c-43e3-9a8b-475aa8bc5460 Co-authored-by: lmajano <137111+lmajano@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes fwreinit server discovery when a CommandBox server is started with a custom web.webroot in server.json by shifting discovery away from CWD/webroot matching and toward server-name-based lookup.
Changes:
- Default the
nameargument to the server name discovered fromserver.json. - Update server discovery to use
getServerInfoByDiscovery( name = ... )instead of CWD-based discovery. - Adjust the “no server found” messaging to include the name being searched for.
| var serverInfo = serverService.getServerInfoByDiscovery( name = arguments.name ); | ||
|
|
||
| if ( !structCount( serverInfo ) ) { |
There was a problem hiding this comment.
Switching to name-only discovery means coldbox reinit can no longer fall back to discovering the running server by the current working directory. If getDefaultServerName() returns an empty string (e.g., no server.json in the CWD or the server isn’t registered), getServerInfoByDiscovery( name = "" ) will likely return no match where the previous CWD-based discovery would have succeeded. Consider adding a fallback: if arguments.name is blank (or the name lookup returns an empty struct), attempt discovery using the CWD (or the server.json path) before failing.
| var serverInfo = serverService.getServerInfoByDiscovery( name = arguments.name ); | |
| if ( !structCount( serverInfo ) ) { | |
| var serverInfo = {}; | |
| // Try name-based discovery first if we have a non-blank name | |
| if ( len( trim( arguments.name ) ) ) { | |
| serverInfo = serverService.getServerInfoByDiscovery( name = arguments.name ); | |
| } | |
| // Fallback: attempt discovery using the server.json in the current working directory | |
| if ( !structCount( serverInfo ) ) { | |
| serverInfo = serverService.getServerInfoByDiscovery( serverConfigFile = "server.json" ); | |
| } | |
| if ( !structCount( serverInfo ) ) { |
When a server is started with a custom
web.webrootinserver.json(common in module development setups usingtest-harnessas the webroot),fwreinitfails with "No server configurations found" because it was discovering servers by matching the CWD against the server's webroot path.Changes
getServerInfoByDiscovery(getCWD(), name)withgetServerInfoByDiscovery(name=arguments.name), bypassing the webroot path mismatch entirelyserver.json— addsgetDefaultServerName()which reads the server name registered inserver.jsonviagetServerInfoByDiscovery(serverConfigFile="server.json"), making thenameparameter self-populating without user inputserver.jsonor unregistered servers by checkingkeyExists("name")before returningprivate function getDefaultServerName(){ var serverInfo = serverService.getServerInfoByDiscovery( serverConfigFile = "server.json" ); return serverInfo.keyExists( "name" ) ? serverInfo.name : ""; }📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.