[Coldbox 6] Can You Have a Route Named “Resources” If That Folder Exists?

In development, I have a folder in my web root called “resources” where my js, scss, and other assets live. However, I’d like to create a handler called “Resources.cfc” with a route of /resources/

Is this possible? When I attempt to access the route /resources/ I get the directory listing of the actual /resources/ folder probably due existing directory with the same name.

If I had to guess, I would need to somehow block/exclude the path from the server.config file and/or from the web.config file if using IIS so ColdFusion doesn’t think the folder exists.

@DaveL You are correct. The rewrite rules in place check for an existing directory or file first, before they forward on to index.cfm for the routes to be handled by Coldbox. You would need to customize a rewrites file to add a condition to forward if the path was /resources. Alternately you could use a different directory for your development assets and, if you are using Coldbox Elixir, you would just need to override that path in your webpack.config.js file.

1 Like

Thanks for the input @jclausen!
If you don’t want to break with folder naming conventions, another approach is to get creative with the web server’s rewrite rules.

Commandbox: server.json

        "rules": [
            "path('/resources/') -> rewrite('/index.cfm/resources')" 
    // rest of file

IIS web.config using static rewrites

<?xml version="1.0" encoding="UTF-8"?>

                <rewriteMap name="StaticRewrites">
                    <add key="/resources/" value="/index.cfm/resources/" />


                <rule name="Static Rewrites" stopProcessing="true">
					<match url=".*" />
						<add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
					<action type="Rewrite" url="{C:1}" appendQueryString="true" />

            	<!-- rest of file... --->