Commandbox fresh app and /index.cfm required?

I completely rewrote this post after setting up a completely fresh app with coldbox app create. I modified the Main handler to duplicate the index() event to about() and media(). I simply changed the prc.welcomeMessage to indicate which event fired.

Under Commandbox (completely new install, so version CommandBox 6.0.0+00787), I cannot get the two events ‘/about’ and ‘/media’ to fire unless I add ‘/index.cfm/’ to the URL.

I know this isn’t right. I also tried adding two routes and retesting:

		// Conventions-Based Routing
		route( '/about' ).to( 'main.about' );
		route( '/media' ).to( 'main.media' );
		route( ":handler/:action?" ).end();

… but that does not help, either. What am I missing? It’s got to be simple. And I’m not just reiniting, I’m using the tray icon to restart the local server. And yes, the line setFullRewrites( true ); is indeed in the Router.cfc.

Works: http://127.0.0.1:59572/index.cfm/media (Fires correctly)
Doesn’t work: http://127.0.0.1:59572/media (404)

Interestingly, clicking on the > Main link also 404’s:
image

Note: I first noticed this in a Docker build where it wasn’t working and local site where it was (same code). I decided to test a completely new, clean site and that testing is what’s in this post now. I get this solved here and I’ll go back to the Docker build testing.

Do you have rewrites enabled? That’s what adds the index.cfm.

By enabled, do you mean the line:

And yes, the line setFullRewrites( true ); is indeed in the Router.cfc.

?

Nope. That is a ColdBox router setting which affects how links are generated to omit the index.cfm in the link text. The actual rewrites are not part of ColdBox MVC. They are part of your web server and add the index.cfm back into the incoming requests. If you’re using CommandBox to run the server, does the server.json have web.rewrites.enable set to true?

No, I see you mean start --rewritesEnable at the box prompt. I have NEVER done this before! Never seen this before! (Learning is hard.)

Okay, how do I set this up for a docker builder, then? Or is there a way to default this, like… forever?

Adding and testing web.rewrites.enable

Yes, it was that way. I guess the app create does this automatically. But… clearly it didn’t work until I added to the command line.

image

I don’t know what to say here. I opened that file, looked at it, did NOT change it, nothing. I did server stop and did server start, this time NOT adding the --rewritesEnable command line, and it worked. I’m telling you, it did NOT work the first time. Or the second or third or fourth… wait… does that command line flag CREATE the server.json?

I’m a little surprised since when you run the

coldbox create app

command, by default it uses this server.json file

which, as you can see, already has rewrites enabled. So usually just spinning up a site and starting the server is all you need to do.

Yes, any CLI args you add to the start command are automatically saved in the JSON file for future starts. But if you use coldbox create app to scaffold out the app, the server.json file should have already been there and ready to go.

It COULD be because I NAMED the site. I had TWO server.json files. When I first ran it, I did the following (in box)

cd c:\Websites\
mkdir trash
cd trash
coldbox app create  (or whatever syntax it is)
server start trash
server stop
cd \websites
server cd trash       to make sure it got named.

Before I noted there were two server.json files…
Yep… deleted both, did server start trash --rewritesEnabled and it created server-trash.json (didn’t realize box did this), and added the content:

{
    "name":"trash",
    "web":{
        "rewrites":{
            "enable":true
        }
    }
}

So… yeah, I didn’t understand that behavior. I’ll go apply it now to the docker build and see if that solves it there, as I suspect it will.

Thanks for late-at-night reply!

Yep, you can put a name in the json like

server set name=foo

and it will work like normal on first start with just

server start

but if you add an explicit name to the start command itself

server start foo

then we assume you plan on having more than one site in that folder like

start name=luceetest cfengine=lucee
start name=adobetest cfengine=adobe

then we suffix the JSON files for you to keep them separate.

./server-luceetest.json
./server-adobetest.json

Be careful when you do this though because the server xxx commands by default like server show name will look in the default file name unless you tell it otherwise.

Understood. Thank you for the advice. (And purpose of it.) I know you’ve done a LOT of work over the years to make Commandbox so great, that’s why I wanted to start with it for my docker build.

And squaring away the server.json (sans name) and using start – enableRewrites just to (lazily) add to the server.json, committing, running my build script and rebuilding the docker image… completely solved the issue and left me with a better undestanding of why some things were working and some were not.

Thanks, now close the computer lid! :smiley:

2 Likes

Good work. Learning new stuff can burn a lot of CPU brain cycles until how it all works starts to click. I think you’ll be pleased with the flexibility of the CommandBox server. Just having the ability to override literally anything with env vars is so handy.

1 Like