Trouble getting web aliases to work

I’m trying to get web aliases to work so that I can run testbox tests, but I’m not succeeding. I am using CommandBox CLI 6.1.0+813 and tested with Lucee 6.1.1.118 and Lucee 5.4.6.9.

I have an app that has this basic folder structure:

> project_root
   > tests
      > Application.cfc
      > runner.cfm
   > wwwroot
      > Application.cfc
      > index.cfm
   > server.json

My server.json file has this basic setup:

{
  "web":{
    "aliases":{
      "/tests":"tests",
      "/sameAsWwwRoot":"wwwroot"
    },
    "bindings":{
      "HTTP":{
        "listen":"80"
      }
    },
    "webroot":"wwwroot"
  }
}

When starting a server with debug mode, it indicates that the aliases are loading and evaluating to the correct folders.

  • “/tests” → “project_root/tests”
  • “/sameAsWwwRoot” → “project_root/wwwroot”

When I navigate to http://localhost/index.cfm, the “project_root/wwwroot/index.cfm” page loads as expected.

But when I navigate to http://localhost/tests/runner.cfm, the following error occurs:

Missing Includes
Page [/tests/runner.cfm] [system-path\project_root\wwwroot\tests\runner.cfm] not found

And when I navigate to http://localhost/sameAsWwwRoot, a similar error occurs:

Missing Includes
Page [/sameAsWwwRoot/index.cfm] [system-path\project_root\wwwroot\sameAsWwwRoot\index.cfm] not found

I’ve noticed that the “modern” ColdBox starter template also is failing TestBox runs because of the same problem.

Does anybody have any suggestions on how to get this working?

This almost looks like a candidate for using multiple “sites”, but I’m not sure what kind of overhead that creates compared to aliases.

Oh, it seems that it’s not a supported feature of Lucee yet, according to Jira: luceeserver LDEV-694. The suggested workaround by @bdw429s include adding a CF mapping in Lucee that maps to the directory.

So I added a .cfconfig.json file (commandbox-cfconfig CLI dependency) to the project with a mapping for each of the directories, and voila! It works! The caveat, though, is that (for relative paths) the server.json web.aliases values are given with respect to server.json. But .cfconfig.json CFMappings are given with respect to the webroot. So the .cfconfig.json file had to be specified with:

{
  "CFMappings":{
    "/tests":{
      "INSPECTTEMPLATE":"",
      "PHYSICAL":"../tests",
      "PRIMARY":"physical",
      "READONLY":"false",
      "TOPLEVEL":"false"
    },
    "/sameAsWwwRoot":{
      "INSPECTTEMPLATE":"",
      "PHYSICAL":"../wwwroot",
      "PRIMARY":"physical",
      "READONLY":"false",
      "TOPLEVEL":"false"
    }
  }
}

Edit:
Err, actually, it looks like when calling http://localhost/tests/runner.cfm, it seems that the Application.cfc file of the wwwroot folder is being referenced instead of the one from the tests folder as I expected.

Why would that be? I thought the Application.cfc file in the same folder would have precedence.

CFConfig actually requires an absolute path for mappings. It’s undefined how the CF engine may interpret a relative path. I’m not surprised Lucee takes it relative to the web root. That is processed entirely by Lucee however, CommandBox and its JSON files are out of the picture at that time. CFConfig performs no path expansions on any settings in the JSON.

As to the Application.cfc behavior, no clue. I’d post in the Lucee forums with Lucee-related questions.

1 Like

Thanks @bdw429s for the insight! I am following up for this problem at: Application.cfc in virtual directory not being used - support - Lucee Dev

For the time being, I’m going to move the tests folder to be a sub-folder of the webroot, as:

> project_root
   > wwwroot
      > tests
         > Application.cfc
         > runner.cfm
      > Application.cfc
      > index.cfm
   > server.json

This fixes all the problems, and for automated container builds I’ll remember to include that sub-folder in the .dockerignore file (though it seems CommandBox in production mode would block that path anyway – safe design!)