{"size": 969, "ext": "js", "max_stars_repo_path": "src/scripts/app-datasource.js", "max_stars_repo_name": "indramahkota/pwapp-indramahkota", "max_stars_repo_stars_event_min_datetime": "2021-04-19T02:21:04.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-19T02:21:04.000Z", "max_issues_repo_path": "src/scripts/app-datasource.js", "max_issues_repo_name": "indramahkota/pwapp-indramahkota", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/scripts/app-datasource.js", "max_forks_repo_name": "indramahkota/pwapp-indramahkota", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 44.0454545455, "max_line_length": 138, "alphanum_fraction": 0.6914344685}
import footballAppConstant from "./app-constants.js";

const customUrl = footballAppConstant.proxyUrl + footballAppConstant.baseUrl;

const getFootballData = async (signal, endPoint) => {
    /* possible error: registered clients are allowed for 10 requests/minute (free plan). */
    /* if requset exceed response will be 429 (Too Many Requests) */
    /* avoid "No Access-Control-Allow-Origin header" */
    /* ref: https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe */
    const response = await fetch(customUrl + endPoint, {
        headers: {
            "X-Auth-Token": footballAppConstant.apiKey
        },
        signal: signal
    });
    if(response !== undefined && response.status === 200) {
        return await Promise.resolve(response.json());
    }
    return await Promise.reject(new Error(`Code: ${response.status}, ${response.statusText}`));
}

export default getFootballData;