Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework Reinit Doesn't Recognize Webroot Setting in server.json #9

Open
homestar9 opened this issue Sep 23, 2024 · 2 comments
Open

Comments

@homestar9
Copy link
Contributor

homestar9 commented Sep 23, 2024

What are the steps to reproduce this issue?

  1. Create a new app using the Ortus Module Template
  2. Add a server.json file to the project root and make sure the web.webroot value is set to test-harness
// example server.json
{
    "name":"myapp",
    "app":{
        "serverHomeDirectory":".engine/lucee5",
        "cfengine":"lucee@5"
    },
    "web":{
        "http":{
            "port":"60301"
        },
        "rewrites":{
            "enable":"true"
        },
        "webroot":"test-harness",
        "aliases":{
            "/moduleroot/myapp":"./",
            "/modules/myapp":"./"
        }
    },
    "openBrowser":"false",
    "cfconfig":{
        "file":".cfconfig.json"
    }
}

  1. Start the server from the root
  2. Try typing fwreinit in Commandbox

What happens?

You will see the error No server configurations found for '[your project folder]', so have no clue what to reinit buddy!

What were you expecting to happen?

The Coldbox-CLI should see the web root and attempt to reinit the framework.

What versions are you using?

Tested with coldbox-cli@be and Commandbox 6.0.0

@homestar9
Copy link
Contributor Author

homestar9 commented Sep 23, 2024

Update:
If I make the following change to Line 29 of reinit.cfc:
var serverInfo = serverService.getServerInfoByDiscovery( name = arguments.name );

The reinit will work if you specify the name of the server like this:
fwreinit name=mymodule

However, I think fwreinit should be smart enough to infer the name from the current working directory server.json file or box.json, if present.

Therefore, I think the fix involves making the change I mentioned above and also changing the default name argument in the run() method to look for a value in the server.json file followed next by box.json.

@homestar9
Copy link
Contributor Author

Update 2:
What about this possible solution?

/**
 * Reinitialize a running ColdBox app if a server was started with CommandBox.
 * This command must be ran from the root of the ColdBox Application
 * .
 * {code:bash}
 * coldbox reinit
 * {code}
 * .
 * {code:bash}
 * coldbox reinit password="mypass"
 * {code}
 **/
component aliases="fwreinit" {

	// DI
	property name="serverService" inject="ServerService";
	property name="formatter"     inject="formatter";

	/**
	 * @password The FWReinit password
	 * @name     Name of the CommandBox server to reinit, will default to the name listed in server.json file
	 * @showUrl  Show the Url to reinit
	 **/
	function run(
		password = "1",
		name     = getDefaultServerName(),
		showUrl  = true
	){
		var serverInfo = serverService.getServerInfoByDiscovery( name = arguments.name );

		if ( !structCount( serverInfo ) ) {
			print.boldRedLine(
				"No server configurations found for '#getCWD()#' and '#arguments.name#', so have no clue what to reinit buddy!"
			);
		} else {
			var thisURL = "#serverInfo.host#:#serverInfo.port#/?fwreinit=#arguments.password#";
			if ( arguments.showUrl ) {
				print.greenLine( "Hitting... #thisURL#" );
			}
			http result="local.results" url="#thisURL#";

			if ( findNoCase( "200", local.results.statusCode ) ) {
				print.boldGreenLine( "App Reinited!" );
			} else {
				print
					.redLine( "status code: #local.results.statusCode#" )
					.redline( "error detail: " & local.results.errorDetail )
					.line( trim( formatter.HTML2ANSI( local.results.filecontent ) ) );
			}
		}
	}
	
	private function getDefaultServerName() {
		return serverService.getServerInfoByDiscovery( serverConfigFile = 'server.json' ).name;
	}

}

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

No branches or pull requests

1 participant