import axios from "axios";
import {goToLoginPage} from "./AdminApi";

const FRONT_BASE_URL = "https://app.axicon.ir/"
const PUBLIC_BASE_URL = "https://pim.liara.run/api/public/"

const axiosParams = {
    withCredentials: true,
    baseURL: PUBLIC_BASE_URL,
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': FRONT_BASE_URL,
    }
}
axios.defaults.withXSRFToken = true
const axiosInstance = axios.create(axiosParams);

const PublicApi = {
    get: async (url) => {
        try {
            const response = await axiosInstance.get(url);
            return response.data
        } catch (error) {
            if (error.response?.status === 419) {
                goToLoginPage()
            } else {
                console.log("error in public get api")
            }
        }
    }
}

export default PublicApi;