Identifying Pre-flight requests in Adapter


#1

Hi,

I need to modify the host in the adapter so I came up with the following:

export default DS.JSONAPIAdapter.extend({ namespace: ‘arp/v2’,

host: function() {
	console.log("Environment is " + ENV.environment);
	
	// We don't want to hardcode the url here.
    if (ENV.environment === 'production' || ENV.environment === 'staging' ) {
        return 'https://www.room.com/arp/wp-json';
    } else {
        return 'http://localhost/arp/index.php/wp-json';
    }
}.property().volatile(), // volatile recalculates on every request

headers: {
	'X-WP-Nonce': 'b67698a8f9',
	'Content-type': 'text/plain'	
 },

});

My problem is that because it uses this for EVERY response it sends the X-WP-Nonce header on pre-flight requests, which causes the server to barf out CORS errors.

If there a way I can test for pre-flight requests and only add the header if it’s NOT pre-flight?


#2

Ok answered my own question, the wp-json has a lot of filters etc you can control what is allowed and not allowed in the way of pre-flight headers