20862be7d0
- slim/slim: ^3.1 - symfony/expression-language: ^3.4 - fxp/composer-asset-plugin: ~1.3 - bower-asset/vue: ^2.5 - bower-asset/vue-resource: ^1.5
30 lines
659 B
JavaScript
30 lines
659 B
JavaScript
/**
|
|
* CORS Interceptor.
|
|
*/
|
|
|
|
import Url from '../../url/index';
|
|
import xdrClient from '../client/xdr';
|
|
import {inBrowser} from '../../util';
|
|
|
|
const SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest();
|
|
|
|
export default function (request) {
|
|
|
|
if (inBrowser) {
|
|
|
|
const orgUrl = Url.parse(location.href);
|
|
const reqUrl = Url.parse(request.getUrl());
|
|
|
|
if (reqUrl.protocol !== orgUrl.protocol || reqUrl.host !== orgUrl.host) {
|
|
|
|
request.crossOrigin = true;
|
|
request.emulateHTTP = false;
|
|
|
|
if (!SUPPORTS_CORS) {
|
|
request.client = xdrClient;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|