-
-
Save lmcneel/4e001000d306109f2969 to your computer and use it in GitHub Desktop.
CF: Using "Access-Control-Allow-Origin" header in ColdFusion CFScript #snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
boolean function onRequestStart( required string targetPage ) { | |
var headers = getHttpRequestData().headers; | |
var origin = ''; | |
var PC = getpagecontext().getresponse(); | |
// Find the Origin of the request | |
if( structKeyExists( headers, 'Origin' ) ) { | |
origin = headers['Origin']; | |
} | |
// If the Origin is okay, then echo it back, otherwise leave out the header key | |
if( listFindNoCase( 'http://www.mysite.com,http://mysite.com', origin ) { | |
PC.setHeader( 'Access-Control-Allow-Origin', origin ); | |
} | |
// Only allow GET requests | |
PC.setHeader( 'Access-Control-Allow-Methods', 'GET' ); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment