Mappings not honored

I’m trying to set up an environment where I can easily run an app I’m developing on different CFML engines, CommdandBox/CFConfig seems perfect.

I have a .CFConfig.json file generated by CFConfig from my actual server setup at the server root.

I can see the correct mappings in the administrator, and I can correctly resolve paths in cf code, like so:

fileExists(expandPath("/MyAppMapping/somefile.cfm"))

But When I try access http://127.0.0.1:8501/MyAppMapping/somefile.cfm, I get File Not Found. In the logs I see the mapping wasn’t resolved, it was looking for {siteRoot}MyAppMapping/somefile.cfm, when the mapping for MyAppMapping points deeper inside the app.

What’s wrong here? (URL rewrites are off, fyi.)

Part 2: I have the same sort of problem with html and other non-CFML files. How can I specify web server mappings for a CommandBox instance?

Thanks in advance for any help, and apologies for asking so many questions. I may not seem like it, but I’ve actually tried to find these infos in the docs before pestering folks here.

Dave,

CFML mappings aren’t the same as HTTP server mappings. From the Adobe docs ( which doesn’t mention components, but those apply too):

ColdFusion mappings let the cfinclude and cfmodule tags access pages that are outside the Web root. If you specify a path that starts with the mapping’s logical path in these tags, ColdFusion looks for the page using the mapping’s directory path.
ColdFusion also uses mappings to find ColdFusion components (CFCs). The cfinvoke and cfobject tags and CreateObject function look for CFCs in the mapped directories.
Note: These mappings are independent of web server virtual directories. If you would like to create a virtual directory to access a given directory through a URL, please consult your web server documentation.

If you need both a CFML and HTTP server mappings, then you will need to use rewrites to configure those HTTP server routes, which correspond to the mappings.

Jon

Thanks Jon, I suspected as much about non-cfm mappings, will investigate what a minimalist rewrite equivalent to a simple mapping looks like.

But for now the bigger problem is that CFM mappings aren’t being applied, as I said. It didn’t find my CFM file either, which it should have from the mapping, even though I can see the mapping in the admin, and can resolve it correctly in cf code.

Or are you saying the direct navigation to CFM files also won’t work without a rewrite rule?

Thanks again,
Dave

What ColdFusion engine are you using? I just tested this locally on Lucee 4.5 and it worked fine.

  1. I started a Lucee server
  2. I created a /foo/bar.cfm file from the web root
  3. I created a /brad mapping in my Lucee admin that pointed to /bar
  4. I hit site.com/brad/bar.cfm in the URL
  5. The contents of the cfm file loaded.

Regarding web server aliases (or virtual directories as they’re called in IIS), the docs for those are here:
https://commandbox.ortusbooks.com/content/embedded_server/aliases.html

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

To Brad’s point: Mappings will be virtually aliased on Lucee if you create the mapping in the administrator and keep the “Make this mapping web-accessible (i.e., accessible via a browser or remote HTTP call)” checked.

Mappings created within the Application.cfc do not support the web aliasing setting, however.

Jon

I appreciate you both jumping in here, much appreciated :slight_smile:

Engine is ACF 2016, though once I get things working I’ll want Lucee and other ACF versions too, that’s the point of this for me.

As I said, the mapping resolves correctly in cf code, so I would expect accessing it directly to work.

Since I need the non-cf mapping anyway for html/js/css, to save me some time and possible wrongness, can one of you tell me what a simple rewrite rule to map a directory look like? (My first encounter with Tuckey…)

I tried this:

^/someDir /foo/bar/someDir

But it doesn’t seem to help, either for direct cfm or html file access.

I also can’t get to the /tuckey-status page to see if it can shed some light. That should be accessible at {serverroot}/tuckey-status, right?

I have this in my server.json:

“rewrites”:{
“configReloadSeconds”:“30”,
“config”:“customRewrites.xml”,
“statusPath”:"/tuckey-status"
}
},

My rewrites file is at the server root, same level as .CFConfig.json and server.json. Is that right?

BTW, the rewrite docs aren’t quite right. They say to use ‘server set web.rewrites.enable=true’, but it seems you really need ‘config set server.defaults.web.rewrites=true’, without ‘.enable’. (See, I actually have been looking at the docs :slight_smile: )

Thanks again.

Update on that rewrite rule:

^/someDir/(.*) /foo/bar/someDir/$1

But still no joy, html or cfm.

I can hit either one directly at the fully-specified path that the mapping resolves to.

Mmmmph. Feeling pretty ignorant here.

As I said, the mapping resolves correctly in cf code, so I would expect accessing it directly to work.

That would be a correct assumption for Lucee (when the box is checked for the mapping) but an incorrect assumption for Adobe CF. Adobe will not let you hit a CF mapping from the URL unless you’ve created a web server alias.

can one of you tell me what a simple rewrite rule to map a directory look like?

Why are you trying to use rewrites for this? CommandBox already supports web aliases. (virtual directories) I sent you the link to the docs in a previous E-mail.
https://commandbox.ortusbooks.com/content/embedded_server/aliases.html

I also can’t get to the /tuckey-status page

As the docs say, the tuckey status page is only active if you have done a --debug start. Did you enable that?
https://commandbox.ortusbooks.com/content/embedded_server/url_rewrites.html#internal-tuckey-status-page

the rewrite docs aren’t quite right. They say to use ‘server set web.rewrites.enable=true’, but it seems you really need ‘config set server.defaults.web.rewrites=true’

You’re confusing two different things. server set will put the setting in your local server.json for this server. config set will set a global config setting in CommandBox. The server.defaults config setting is the default settings to use for all servers that don’t override the settings locally.

without ‘.enable’.

Nope, the enable is needed. Did you see that in the docs somewhere? If so, that’s a typo.

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Apologies for my various confusions Brad, and thanks for your patience while I work out the various variables in play here.

After narrowing things down, it appears that with both cf mappings and aliases in place, things work correctly, but only if both mappings and aliases use full absolute paths.

What was tripping me up was that aliases with a relative path seem not to resolve correctly (or at any rate, how I wanted them to) in some situations. For instance I have this alias:

“/mapping-test”:"/mapping-test/foo/bar/mapping-test"

When I go to {server}/mapping-test/index.html, it doesn’t find the file at {server}\mapping-test\foo\bar\mapping-test\index.html. Is that expected?

It’s not a huge deal, I can use an absolute path, like for mappings, which have always been absolute. Relative paths for both would make server.json files more portable, but absolute for both seems to get me where I need to be.

Just to say it, these are GREAT tools Brad! The ability to pretty near instantly run the same code on different CFML engines, with the same datasources (and databases), the same mappings and settings, and without multiple copies of the code, or configuring and spinning up separate VMs, or Windows services etc – I expect this tech to radically simplify my dev life.

I have some further questions about living life in that world, will ask in a separate thread.

Thanks again for your help, and for these tools,
Dave

“/mapping-test”:"/mapping-test/foo/bar/mapping-test"
When I go to {server}/mapping-test/index.html, it doesn’t find the file at {server}\mapping-test\foo\bar\mapping-test\index.html. Is that expected?

That’s not a relative path, that’s an absolute path. In CommandBox, any path starting with a leading slash is considered absolute. On Windows, this is in agreement to how DOS works.
https://commandbox.ortusbooks.com/content/usage/parameters/file_paths.html
(Don’t feel bad if you haven’t see that page in the docs, I just added it this week after some of our E-mails to help clarify these things)

So the mapping you’re really creating is most likely:
“/mapping-test”:“C:/mapping-test/foo/bar/mapping-test”
since a leading slash resolves to the current drive root. Relative paths should not start with a leading slash at all, but a folder name or …/ instead.

If you want to debug this, you can do a --debug --console start and CommandBox will output information to the console on every web page that’s hit that shows what the URL is resolving to which includes information about web aliases. You may need to upgrade --debug to --trace. Test it and see what you get.

Thanks again for your help, and for these tools,

You’re very welcome :slight_smile:

Thanks!

~Brad

ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Ah, got it, works perfectly.

It appears you can specify libDirs the same way, as relative paths.

This is awesome, means there are no absolute paths in my server-xxx.json files, they’re completely portable.

Great stuff Brad.