39 lines
911 B
TypeScript
39 lines
911 B
TypeScript
import RequestType from "../types/RequestType.ts";
|
|
import GenericObject from "../types/GenericObject.ts";
|
|
|
|
enum MessagingType {
|
|
GET_RESPONSE_WITHOUT_CORS = 'getResponseWithoutCors',
|
|
SET_RESPONSE_WITHOUT_CORS = 'setResponseWithoutCors',
|
|
}
|
|
|
|
|
|
type GetResponseWithoutCors = {
|
|
url: string;
|
|
method: string;
|
|
data ? : GenericObject | string;
|
|
requestKey: string;
|
|
requestType ? : RequestType;
|
|
headers ? : GenericObject | null;
|
|
}
|
|
|
|
export const getResponseWithoutCors = ({
|
|
url,
|
|
method,
|
|
data = {},
|
|
requestKey,
|
|
requestType = RequestType.JSON,
|
|
headers = null}: GetResponseWithoutCors) => {
|
|
window.postMessage({
|
|
type: MessagingType.GET_RESPONSE_WITHOUT_CORS,
|
|
data: {
|
|
url,
|
|
method,
|
|
data,
|
|
requestKey,
|
|
requestType,
|
|
headers
|
|
}
|
|
});
|
|
};
|
|
|
|
export default getResponseWithoutCors; |