Elixir + Coldbox is a powerful duo for developing modern web apps and introduces some convenient conventions for developers to keep things organized. One of these conventions is storing raw SCSS/JS source files in a /resources/ folder in the web root.
However, I’ve been having a hard time creating and using a handler with the name “resources” because it conflicts with the actual directory “/resources/”.
If you try and bring up the URL: http://127.0.0.1:58534/resources/, I would expect it to trigger the index()
action within the resources
handler, however because the folder /resources/ exists, the web server shows the contents of the directory. In development, it looks like this:
I assume the fix is to tell the web server to let Coldbox handle the request through a new URL rewrite mapping, but everything I’ve tried doesn’t seem to work. Here’s what I’ve tried so far:
- Start the server with --debug flag.
- Keep a console open via server log --follow
- Set up server.json to use a custom rewrites file as follows:
{
"web":{
"rewrites":{
"enable":"true",
"config":"customRewrites.xml",
"configReloadSeconds":"30",
"statusPath":"/tuckey-status"
}
},
"app":{
"cfengine":"adobe@2018",
"_prior_cfengine":"lucee"
},
"name":"myapp"
}
I learned early on that I have to copy/paste the default rewrite rule Coldbox needs at the beginning of the customRewrites.xml file. My idea was to then follow up with an additional rule to pass through the exact URL /resources/ and pass through the request to index.cfm like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
<!-- Turn resources/ into /index.cfm/resources/ -->
<rule>
<from>^/resources$</from>
<to type="passthrough">/index.cfm/resources</to>
</rule>
<rule>
<note>Generic Front-Controller URLs</note>
<!-- These are paths that don't exist on disk, but shouldn't get rewritten since the CF engine treats them special. -->
<condition type="request-uri" operator="notequal">^/(flex2gateway|flashservices/gateway|messagebroker|lucee|rest|cfide|CFIDE|cfformgateway|jrunscripts|cf_scripts|mapping-tag|CFFileServlet)/.*</condition>
<!-- This is a special URL that can be enabled with debugging -->
<condition type="request-uri" operator="notequal">^/tuckey-status</condition>
<!-- Used for the Adobe CF 2018 performance monitoring service -->
<condition type="request-uri" operator="notequal">^/pms$</condition>
<!-- Browsers like to send this request and it will get rewritten to /index.cfm/favicon.ico when it really just needs to be a 404 -->
<condition type="request-uri" operator="notequal">^/favicon.ico</condition>
<!-- Ignore any path to a .cfm or .cfml file in a sub directory that has a path info attached. These won't trigger as "real" directories below
since the rewrite filter doesn't know what part is the actual file name. Note, the ses path info servlet filter hasn't fired yet. -->
<condition type="request-uri" operator="notequal">^/.*\.cf(m|ml)/.*</condition>
<!-- Do not rewrite paths that point to real files or directories -->
<condition type="request-filename" operator="notdir"/>
<condition type="request-filename" operator="notfile"/>
<!-- Turn localhost/foo into localhost/index.cfm/foo -->
<from>^/(.+)$</from>
<to type="passthrough">/index.cfm/$1</to>
</rule>
</urlrewrite>
Unfortunately, my debug output produces this:
If anyone has any tips for how I need to modify customRewrites.xml, your assistance would be most appreciated!