UNPKG

@varandas/clash-royale-api

Version:

A Clash Royale API official wrapper for seamless integration with your applications.

38 lines 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAxiosInstance = void 0; const axios_1 = __importDefault(require("axios")); const constants_1 = require("../constants"); /** * Create a default request configuration * object for axios. */ const defaultRequestConfig = { baseURL: constants_1.BASE_ENDPOINT, headers: { 'Content-Type': 'application/json', }, }; /** * Creates an axios instance with the required * Authorization headers to use the official api. * * @param {string} token - The api token from https://developer.clashroyale.com * @param {string} baseUrl - The base url for the api (optional) */ const getAxiosInstance = (token, baseUrl) => { const authorization = `Bearer ${token}`; defaultRequestConfig.headers = { ...defaultRequestConfig.headers, authorization, }; if (baseUrl) { defaultRequestConfig.baseURL = baseUrl; } return axios_1.default.create(defaultRequestConfig); }; exports.getAxiosInstance = getAxiosInstance; //# sourceMappingURL=index.js.map