Skip to content

Commit

Permalink
fix(client): fix adding custom headers (#212)
Browse files Browse the repository at this point in the history
* fix(client): fix adding custom headers

* revert some changes

* fix updating baseURL of client instance

* v0.0.5

* board always use latest version of client
  • Loading branch information
laurentlp committed Oct 19, 2021
1 parent f4ecbca commit b92ca08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/board/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@botpress/webchat": "0.0.1",
"@botpress/webchat-skin": "0.0.1",
"@botpress/messaging-client": "0.0.4",
"@botpress/messaging-client": "",
"axios": "^0.21.1"
}
}
6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botpress/messaging-client",
"version": "0.0.4",
"version": "0.0.5",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"source": "src/index.ts",
Expand All @@ -15,7 +15,7 @@
],
"devDependencies": {},
"dependencies": {
"axios": "^0.21.1",
"@botpress/messaging-base": "0.0.1"
"@botpress/messaging-base": "0.0.1",
"axios": "^0.21.1"
}
}
11 changes: 7 additions & 4 deletions packages/client/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ export class MessagingClient {

public authenticate(clientId: string, clientToken: string) {
this.auth = { clientId, clientToken }
this.authHttp.defaults.headers['x-bp-messaging-client-id'] = clientId
this.authHttp.defaults.headers['x-bp-messaging-client-token'] = clientToken
this.authHttp.defaults.headers.common['x-bp-messaging-client-id'] = clientId
this.authHttp.defaults.headers.common['x-bp-messaging-client-token'] = clientToken
}

private configureHttpClient(client: AxiosInstance | undefined, config: AxiosRequestConfig) {
if (client) {
client.defaults = { ...client.defaults, ...config }
client.interceptors.request.use((value) => {
return { ...value, ...config }
})

return client
} else {
return axios.create(config)
}
}

private getAxiosConfig({ url }: MessagingOptions): AxiosRequestConfig {
return { baseURL: `${url}/api`, headers: {} }
return { baseURL: `${url}/api` }
}
}

Expand Down

0 comments on commit b92ca08

Please sign in to comment.