OK. So, I have a problem with:
REST API on Lucee 4.5, IIS7, Windows 2008R2
Background:
Production Server:
I installed Lucee 4.5 from the official installed, about 2 years ago.
I set up 3 BonCode Handler Mappings for:
*.cfc
*.cfml
*.cfm
My website works fine.
Last week, I decided to set up a REST API instance, using:
this.webAdminPassword = “[my_web_admin_password]”;
RestInitApplication(“[system_path_to_wwwroot]/com/api/v1”,“api”);
So, my endpoint should be:
https://www.mydomain.com/rest/api/
And an example request URL:
https://www.mydomain.com/rest/api/tokenService/token
TokenService.cfc
<cfscript>
component rest="true" restPath="tokenService" {
remote struct function getToken() httpmethod="get" restPath="/token" produces="application/json" {
return {token: generateSecretKey(request.crptographyalgorithm)};
}
}
</cfscript>
I have done tests to validate that the REST API has been initialised correctly.
On my laptop, I use a developer’s version of ACF11, using port 8500. The REST API works perfectly.
On my production server, whenever I make a REST API request, I get a 404, “Page Not Found” response.
Lucee REST API settings:
In my ‘web.xml’ file found in [system_path_to_C_drive]\Lucee\Tomcat\conf
<servlet>
<description>Lucee Servlet for RESTful services</description>
<servlet-name>RestServlet</servlet-name>
<servlet-class>lucee.loader.servlet.RestServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- mapping for Lucee's REST servlet -->
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have both REST API XML blocks uncommented. I have not changed these settings in any way. Essentially, all REST API requests must match /rest/*
web.config:
In my ‘web.config’ file, I have settings for custom pages to handle 404 responses.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="400" subStatusCode="-1" />
<error statusCode="400" path="https://www.mydomain.com/exception/error/" responseMode="Redirect" />
<remove statusCode="403" subStatusCode="-1" />
<error statusCode="403" path="https://www.mydomain.com/exception/forbidden/" responseMode="Redirect" />
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="https://www.mydomain.com/exception/page-not-found/" responseMode="Redirect" />
</httpErrors>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="Imported Rule 1">
<match url="^([a-zA-Z0-9/-]+(index\.cfm)*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{DOCUMENT_ROOT}{URL}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/default{URL}" />
</rule>
<rule name="Imported Rule 2">
<match url="(.*[^cms|^help]\/teachers)\/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}/?name={R:2}" />
</rule>
<rule name="Imported Rule 3">
<match url="(.*[^cms|^help]\/contributors)\/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}/?name={R:2}" />
</rule>
<rule name="Imported Rule 4">
<match url="(.*groups)\/(.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}/?groups={R:2}" />
</rule>
<rule name="Imported Rule 5">
<match url="(.*login)\/demo$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}/?demomode=true" />
</rule>
<rule name="Imported Rule 6">
<match url="(.*)\/mobile$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}/?mobileuser=true" />
</rule>
<rule name="Imported Rule 7">
<match url="(.*[^cms]\/help\/)(.*[^\.])$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}index.cfm/{R:2}" />
</rule>
<rule name="Imported Rule 8">
<match url="(.*\/catalog\/schedule\/)(january\/|february\/|march\/|april\/|may\/|june\/|july\/|august\/|september\/|october\/|november\/|december\/)*([0-9]+)(\/.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}{R:2}?categoryid={R:3}" />
</rule>
<rule name="Imported Rule 9">
<match url="(.*\/catalog\/category\/)(a\/|b\/|c\/|d\/|e\/|f\/|g\/|h\/|i\/|j\/|k\/|l\/|m\/|n\/|o\/|p\/|q\/|r\/|s\/|t\/|u\/|v\/|w\/|x\/|y\/|z\/)*([0-9]+)(\/.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}{R:2}?categoryid={R:3}" />
</rule>
<rule name="Imported Rule 10">
<match url="(.*\/catalog\/schedule\/)(january\/|february\/|march\/|april\/|may\/|june\/|july\/|august\/|september\/|october\/|november\/|december\/)*(.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}{R:2}" />
</rule>
<rule name="Imported Rule 11">
<match url="(.*\/catalog\/category\/)(a\/|b\/|c\/|d\/|e\/|f\/|g\/|h\/|i\/|j\/|k\/|l\/|m\/|n\/|o\/|p\/|q\/|r\/|s\/|t\/|u\/|v\/|w\/|x\/|y\/|z\/)*(.*)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}{R:2}" />
</rule>
</rules>
</rewrite>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/octet-stream" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
<system.web>
<customErrors mode="Off" />
<httpRuntime maxRequestLength="1048576" executionTimeout="10000" />
</system.web>
</configuration>
Other:
The REST API CFCs, reside in a sub directory of my website root. So, this is not a dedicated REST API server!
QUESTION
Can anyone shed any light, as to why I cannot makes successful REST API requests?