-
-
Save LCHCAPITALHUMAIN/35aaa6097ee6372a2e0de353683138be 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