Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapped onApplicationStart() for applicationStop() where possible and… #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 27 additions & 38 deletions core/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,27 @@
<cfargument name="targetPath" default="" />
<cfset var local = structNew() />
<cfset request.unhandled = false />
<cfset local.reloadedInThisRequest = false />
<cfset request.taffyReloaded = false />
<!--- this will probably happen if taffy is sharing an app name with an existing application so that you can use its application context --->
<cfif not structKeyExists(application, "_taffy")>
<cfset onApplicationStart() />
<cfset local.reloadedInThisRequest = true />
</cfif>

<cfif !isUnhandledPathRequest(arguments.targetPath)>
<!---if the path is handled then we pass it along to onRequest--->
<cfelse>
<!--- allow pass-thru for selected paths --->
<cfset structDelete(this, 'onRequest') />
<cfset structDelete(variables, 'onRequest') />
<cfset request.unhandled = true />
</cfif>

<cfreturn true />
</cffunction>

<cffunction name="onRequestEnd">
<cfargument name="targetPage" />

<!--- allow reloading --->
<cfif
(
Expand All @@ -90,41 +104,15 @@
OR
(
application._taffy.settings.reloadOnEveryRequest eq true
)
OR(
isdefined("variables.framework.docs.apiVersion")
AND
variables.framework.docs.apiVersion neq application._taffy.settings.docs.apiVersion
)>
<cfif !local.reloadedInThisRequest and !isUnhandledPathRequest(arguments.targetPath)><!--- prevent double reloads --->
<cfset onApplicationStart() />
</cfif>
</cfif>
<cfif !isUnhandledPathRequest(arguments.targetPath)>
<!--- if browsing to root of api, show dashboard --->
<cfset local.path = replaceNoCase(cgi.path_info, cgi.script_name, "") />
<cfif
NOT structKeyExists(url,application._taffy.settings.endpointURLParam)
AND NOT structKeyExists(form,application._taffy.settings.endpointURLParam)
AND len(local.path) lte 1
AND listFindNoCase(cgi.script_name, "index.cfm", "/") EQ listLen(cgi.script_name, "/")>
<cfif NOT application._taffy.settings.disableDashboard>
<cfif StructKeyExists( URL, "docs" )>
<cfinclude template="#application._taffy.settings.docsPath#" />
<cfelse>
<cfinclude template="../dashboard/dashboard.cfm" />
</cfif>
<cfabort />
<cfelse>
<cfif len(application._taffy.settings.disabledDashboardRedirect)>
<cflocation url="#application._taffy.settings.disabledDashboardRedirect#" addtoken="false" />
<cfabort />
<cfelseif application._taffy.settings.showDocsWhenDashboardDisabled IS False>
<cfset throwError(403, "Forbidden") />
</cfif>
</cfif>
</cfif>
<cfelse>
<!--- allow pass-thru for selected paths --->
<cfset structDelete(this, 'onRequest') />
<cfset structDelete(variables, 'onRequest') />
<cfset request.unhandled = true />
<cfset applicationStop() />
</cfif>

<cfreturn true />
</cffunction>

Expand Down Expand Up @@ -218,14 +206,14 @@
<cfelse>
<cfinclude template="../dashboard/dashboard.cfm" />
</cfif>
<cfabort />
<cfreturn true />
<cfelse>
<cfif len(application._taffy.settings.disabledDashboardRedirect)>
<cflocation url="#application._taffy.settings.disabledDashboardRedirect#" addtoken="false" />
<cfabort />
<cfreturn true />
<cfelseif application._taffy.settings.showDocsWhenDashboardDisabled>
<cfinclude template="#application._taffy.settings.docsPath#" />
<cfabort />
<cfreturn true />
<cfelse>
<cfset throwError(403, "Forbidden") />
</cfif>
Expand Down Expand Up @@ -1076,6 +1064,7 @@
<cfcontent reset="true" />
<cfset addHeaders(arguments.headers) />
<cfheader statuscode="#arguments.statusCode#" statustext="#arguments.msg#" />
<cfset onRequestEnd()>
<cfabort />
</cffunction>

Expand Down