From eedad4f0439af82d2780d03db935492a5c8f5a45 Mon Sep 17 00:00:00 2001 From: Tee Date: Mon, 22 Mar 2021 00:39:23 -0400 Subject: [PATCH] Set API key header with environment variable --- src/client.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index e51ba63..b9e086f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7,12 +7,17 @@ export class Client { static async get(resource: string, params?: IQuery[] | string): Promise { 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; } -} \ No newline at end of file +}