{"size": 727, "ext": "js", "max_stars_repo_path": "utils/axios_request.js", "max_stars_repo_name": "jiasilu/mattermost-webapp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "utils/axios_request.js", "max_issues_repo_name": "jiasilu/mattermost-webapp", "max_issues_repo_issues_event_min_datetime": "2020-11-03T08:28:16.000Z", "max_issues_repo_issues_event_max_datetime": "2020-11-03T08:28:30.000Z", "max_forks_repo_path": "utils/axios_request.js", "max_forks_repo_name": "jiasilu/mattermost-webapp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 25.0689655172, "max_line_length": 67, "alphanum_fraction": 0.6850068776}
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import axios from 'axios';

import {getHostURL} from './utils';

export let axiosInstance;

function newAxiosInstance() {
    const AxiosInstance = axios.create({
        baseURL: getHostURL(),
    });

    // default response handler
    AxiosInstance.interceptors.response.use((response) => response,
        (error) => Promise.reject(error));
    return AxiosInstance;
}

export function getAxiosInstance(independentInstance = false) {
    if (independentInstance) {
        return newAxiosInstance();
    }
    if (!axiosInstance) {
        axiosInstance = newAxiosInstance();
    }
    return axiosInstance;
}
