From 3785bd3114ae6a4402828f9a86d478551317dec4 Mon Sep 17 00:00:00 2001 From: Laimonas Rastenis Date: Tue, 18 Jun 2019 15:40:34 +0300 Subject: [PATCH] Update: Added possibility to provide default request headers --- src/models.ts | 5 +++++ src/request-helper.ts | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/models.ts b/src/models.ts index 6bb276a..6c99176 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,3 +1,7 @@ +interface IHeaders { + [header: string]: string; +} + interface IConfig { baseUrl: string; key: string; @@ -6,6 +10,7 @@ interface IConfig { password: string; tokenRequest: any; accessToken: string; + defaultHeaders: IHeaders; } export interface ITrustpilotApiConfig extends Partial {} diff --git a/src/request-helper.ts b/src/request-helper.ts index 29ed0f0..16f1490 100644 --- a/src/request-helper.ts +++ b/src/request-helper.ts @@ -6,8 +6,11 @@ export class RequestHelper { constructor(private accessProvider: AccessProvider) {} get basicRequest() { + const headers = this.accessProvider.trustpilotApiConfig.defaultHeaders || {}; + return rp.defaults({ baseUrl: this.accessProvider.trustpilotApiConfig.baseUrl, + headers, json: true, }); }