Skip to content

Commit 525e7da

Browse files
authored
Merge pull request #1112 from meilisearch/update_authorization_header
Update authorization header
2 parents ab8ba6f + af34c66 commit 525e7da

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/lib/http-requests.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
import { httpResponseErrorHandler, httpErrorHandler } from '../errors'
1212

1313
class HttpRequests {
14-
headers: {}
14+
headers: Record<string, any>
1515
url: URL
1616

1717
constructor(config: Config) {
18-
this.headers = {
19-
...(config.headers || {}),
20-
'Content-Type': 'application/json',
21-
...(config.apiKey ? { 'X-Meili-API-Key': config.apiKey } : {}),
18+
this.headers = config.headers || {}
19+
this.headers['Content-Type'] = 'application/json'
20+
if (config.apiKey) {
21+
this.headers['Authorization'] = `Bearer ${config.apiKey}`
2222
}
2323
this.url = new URL(config.host)
2424
}
@@ -41,7 +41,7 @@ class HttpRequests {
4141
url: string
4242
params?: { [key: string]: any }
4343
body?: any
44-
config?: Partial<Request>
44+
config?: Record<string, any>
4545
}) {
4646
const constructURL = new URL(url, this.url)
4747
if (params) {
@@ -76,19 +76,19 @@ class HttpRequests {
7676
async get(
7777
url: string,
7878
params?: { [key: string]: any },
79-
config?: Partial<Request>
79+
config?: Record<string, any>
8080
): Promise<void>
8181

8282
async get<T = any>(
8383
url: string,
8484
params?: { [key: string]: any },
85-
config?: Partial<Request>
85+
config?: Record<string, any>
8686
): Promise<T>
8787

8888
async get(
8989
url: string,
9090
params?: { [key: string]: any },
91-
config?: Partial<Request>
91+
config?: Record<string, any>
9292
): Promise<any> {
9393
return await this.request({
9494
method: 'GET',
@@ -102,21 +102,21 @@ class HttpRequests {
102102
url: string,
103103
data: IndexRequest,
104104
params?: { [key: string]: any },
105-
config?: Partial<Request>
105+
config?: Record<string, any>
106106
): Promise<IndexResponse>
107107

108108
async post<T = any, R = EnqueuedUpdate>(
109109
url: string,
110110
data?: T,
111111
params?: { [key: string]: any },
112-
config?: Partial<Request>
112+
config?: Record<string, any>
113113
): Promise<R>
114114

115115
async post(
116116
url: string,
117117
data?: any,
118118
params?: { [key: string]: any },
119-
config?: Partial<Request>
119+
config?: Record<string, any>
120120
): Promise<any> {
121121
return await this.request({
122122
method: 'POST',
@@ -131,21 +131,21 @@ class HttpRequests {
131131
url: string,
132132
data: IndexOptions | IndexRequest,
133133
params?: { [key: string]: any },
134-
config?: Partial<Request>
134+
config?: Record<string, any>
135135
): Promise<IndexResponse>
136136

137137
async put<T = any, R = EnqueuedUpdate>(
138138
url: string,
139139
data?: T,
140140
params?: { [key: string]: any },
141-
config?: Partial<Request>
141+
config?: Record<string, any>
142142
): Promise<R>
143143

144144
async put(
145145
url: string,
146146
data?: any,
147147
params?: { [key: string]: any },
148-
config?: Partial<Request>
148+
config?: Record<string, any>
149149
): Promise<any> {
150150
return await this.request({
151151
method: 'PUT',
@@ -160,19 +160,19 @@ class HttpRequests {
160160
url: string,
161161
data?: any,
162162
params?: { [key: string]: any },
163-
config?: Partial<Request>
163+
config?: Record<string, any>
164164
): Promise<void>
165165
async delete<T>(
166166
url: string,
167167
data?: any,
168168
params?: { [key: string]: any },
169-
config?: Partial<Request>
169+
config?: Record<string, any>
170170
): Promise<T>
171171
async delete(
172172
url: string,
173173
data?: any,
174174
params?: { [key: string]: any },
175-
config?: Partial<Request>
175+
config?: Record<string, any>
176176
): Promise<any> {
177177
return await this.request({
178178
method: 'DELETE',

0 commit comments

Comments
 (0)