forked from boltz/CFShorty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Application.cfc
40 lines (31 loc) · 1019 Bytes
/
Application.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<cfcomponent output="true">
<cfset this.name = "cfmlShorty">
<cfset this.ApplicationTimeOut = createTimeSpan(0,2,0,0)>
<cffunction name="onApplicationStart">
<cfset application.dsn = "cfmlShorty">
<cfset application.api = createObject("component","urlShortner.v1.api").init()>
</cffunction>
<cffunction name="onRequestStart">
<cfset var insert = "">
<cfparam name="url.label" default="">
<cfif structKeyExists(url,"kickstart")>
<cfset onApplicationStart()>
</cfif>
<cfif structKeyExists(url,"url")>
<cfset insert = application.api.insert(longURL=url.url, cgi=cgi, label=url.label)>
<cfset insert = deserializeJSON(insert)>
<cfoutput>http://#insert.shortURL#</cfoutput>
<cfabort>
<cfreturn>
</cfif>
<cfif structKeyExists(url, "shortURL")>
<cfset var get ="">
<cfset get = application.api.get(shortURL=url.shortURL, cgi=cgi)>
<cfdump var="#get#">
</cfif>
</cffunction>
<cffunction name="onApplicationStop">
<cfset application.mongo.close()>
<cfreturn>
</cffunction>
</cfcomponent>