Skip to content

Instantly share code, notes, and snippets.

@christierney402
Last active January 4, 2021 10:51
Show Gist options
  • Save christierney402/5391795 to your computer and use it in GitHub Desktop.
Save christierney402/5391795 to your computer and use it in GitHub Desktop.
CF: Using "Access-Control-Allow-Origin" header in ColdFusion CFScript #snippet
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