85 lines
2.7 KiB
JavaScript
85 lines
2.7 KiB
JavaScript
import axios from "axios"
|
|
import {string} from "yup";
|
|
|
|
|
|
axios.interceptors.request.use(
|
|
config => {
|
|
config.headers = {
|
|
Accept: "application/json",
|
|
"Access-Control-Allow-Origin": "*",
|
|
// "Access-Control-Expose-Headers": "Access-Control-Allow-Origin",
|
|
// "Access-Control-Allow-Headers": "Origin, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token",
|
|
// "Content-Type": "application/json;charset=UTF-8",
|
|
// 'Authorization': (localStorage && localStorage.getItem('access_token')) ? `Bearer ${localStorage.getItem('access_token')}` : '',
|
|
};
|
|
// config.headers['Authorization'] = `Bearer ${localStorage.getItem('token')}`;
|
|
// config.baseURL = process.env.REACT_APP_MAIN_API
|
|
return config;
|
|
},
|
|
error => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
|
|
const blogBasePath = () => {
|
|
return 'https://blogdata.chiefsoft.net';
|
|
}
|
|
|
|
const siteServerPath = () => {
|
|
return process.env.NEXT_PUBLIC_APP_MAIN_API;
|
|
}
|
|
|
|
const postAuxEnd = (basePath, path, postData) => {
|
|
// const basePath = media ? process.env.NEXT_PUBLIC_APP_MAIN_API : process.env.NEXT_PUBLIC_APP_MAIN_API;
|
|
let newPostData = {}
|
|
if (!media) {
|
|
newPostData = {...postData}
|
|
} else {
|
|
newPostData = new FormData();
|
|
for (let data in postData) {
|
|
newPostData.append(data, postData[data]);
|
|
}
|
|
}
|
|
return axios.post(`${basePath}${path}`, newPostData).then(res => {
|
|
return res
|
|
}).catch(err => {
|
|
// throw new Error(err.response.data.error_message);
|
|
throw new Error(err);
|
|
})
|
|
}
|
|
|
|
const getAuxEnd = (basePath, path, reqData = null) => {
|
|
// const basePath = 'https://blogdata.chiefsoft.net'
|
|
return axios.get(`${basePath}${path}`, {params: reqData}).then(res => {
|
|
return res
|
|
// localStorage.clear();
|
|
// window.location.href = `/login?sessionExpired=true`;
|
|
}).catch(err => {
|
|
throw new Error(err);
|
|
// throw new Error(err.response.data.message);
|
|
// return err
|
|
})
|
|
}
|
|
|
|
// FUNCTION TO GET MERMS BLOGS
|
|
export const getMermsBlogs = (reqData) => {
|
|
let postData = {
|
|
...reqData
|
|
}
|
|
return getAuxEnd(blogBasePath(), '/mermsblogdata/mermsemr', postData)
|
|
}
|
|
|
|
export const serMermsWebContact = (reqData) => {
|
|
let postData = {
|
|
...reqData
|
|
}
|
|
return getAuxEnd(siteServerPath(), '/mermsblogdata/mermsemr', postData)
|
|
}
|
|
|
|
export const sendContactMsg = (reqData) => {
|
|
let postData = {
|
|
...reqData
|
|
}
|
|
return postAuxEnd(siteServerPath(), '/website/contact', postData)
|
|
}
|