Set API key header with environment variable

This commit is contained in:
Tee
2021-03-22 00:39:23 -04:00
parent 47861f3760
commit eedad4f043

View File

@ -7,12 +7,17 @@ export class Client {
static async get(resource: string, params?: IQuery[] | string): Promise<any> {
let url: string = `${this.apiUrl}/${resource}`;
const POKEMONTCG_API_KEY = process.env.POKEMONTCG_API_KEY;
const config: axios.AxiosRequestConfig = {
headers: {
'Content-Type': 'application/json'
}
};
if (POKEMONTCG_API_KEY) {
config.headers['X-Api-Key'] = POKEMONTCG_API_KEY;
}
if(typeof params === 'string') url += `/${params}`;
else url += `?${this.paramsToQuery(params)}`;
@ -34,4 +39,4 @@ export class Client {
return query;
}
}
}