2

I am attempting to set up an API site in ColdFusion using FW/1, using subsystems. I would like to set up the routes to omit index.cfm and use /subsystem/action/item for the default paths, but I'm not sure if there is a way to do this. The documentation isn't very clear, from what I can find and other questions out there are very old.

Right now, I have the following in my Application.cfc...

variables.framework = {
        trace = false,
        reloadApplicationOnEveryRequest = "true",
        home = "main.default",
        diComponent = "framework.ioc",
        diLocations = "/model,/controllers",
        SESOmitIndex = true
};

variables.framework.routes = [
        { "$GET/accounts:member/membercount" = "/account/member/membercount" }
];

This is resulting in a 404 error in IIS. Any suggestions?

UPDATE: I did find that I need to update IIS to include a URL Rewrite in order to omit the index.cfm, however, I still get a 404 when I attempt to call http://example.com/account/member/membercount

If I change the URL to http://example.com/account:member/membercount I get an IIS error, "A potentially dangerous Request.Path value was detected from the client (:)".

I would prefer to call the URL the first way, using a "/" instead of the ":" but I'm not sure how to do it. It seems like the routes should be able to handle this, but I haven't been able to find a way so far.

Carl
  • 1,246
  • 3
  • 21
  • 39
  • `account` or `accounts`? Your `Application.cfc` snippet says accounts. Your sample link has no s in the end – Bernhard Döbler Feb 21 '18 at 22:09
  • I'm just playing with subsystems in FW1 and searching the internet by pure chance I come back to this question. I had expected something like `{ "$GET/accounts/member/membercount/$" = "/account:member.membercount" }` would work but it does not in my setup. Might have to do with the way the pathinformation arrives at the application server. There are some possible points of failure. – Bernhard Döbler Jul 14 '18 at 02:32

1 Answers1

0

This is very late but:

It seems you are trying to use search engine friendly URL. You need this generateSES = true in your variables.framework.

And you don't need this:

variables.framework.routes = [
    { "$GET/accounts:member/membercount" = "/account/member/membercount" }
];

as this is made obvious by using generateSES option.

And then this in web.config file in the root folder

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Rewrite for accounts">
                    <match url="^accounts/(.*)" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/accounts:{R:1}" />
                </rule>

                <rule name="RewriteUserFriendlyURL1">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.cfm/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

This tells IIS to handle all the URLs with index.cfm file in the root folder(omitting index.cfm from URL). Now you can use your FW1 routes to tell which controller is to be executed if it is not obvious.

This also removes : from the url structure by rewriting the / next to Subsystem Name to :.

Binod Kalathil
  • 1,939
  • 1
  • 30
  • 43