1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

fix: If the request client has already been instantiated, update config

This commit is contained in:
2021-09-09 11:03:48 +05:00
parent d52c5b26a0
commit 9c099b899c
2 changed files with 29 additions and 16 deletions

View File

@@ -917,6 +917,11 @@ export default class SASjs {
this.sasjsConfig.serverUrl,
this.sasjsConfig.allowInsecureRequests
)
} else {
this.requestClient.setConfig(
this.sasjsConfig.serverUrl,
this.sasjsConfig.allowInsecureRequests
)
}
this.jobsPath =

View File

@@ -52,25 +52,14 @@ export class RequestClient implements HttpClient {
protected csrfToken: CsrfToken = { headerName: '', value: '' }
protected fileUploadCsrfToken: CsrfToken | undefined
protected httpClient: AxiosInstance
protected httpClient!: AxiosInstance
constructor(protected baseUrl: string, allowInsecure = false) {
const https = require('https')
if (allowInsecure && https.Agent) {
this.httpClient = axios.create({
baseURL: baseUrl,
httpsAgent: new https.Agent({
rejectUnauthorized: !allowInsecure
})
})
} else {
this.httpClient = axios.create({
baseURL: baseUrl
})
}
this.instantiateHttpClient(baseUrl, allowInsecure)
}
this.httpClient.defaults.validateStatus = (status) =>
status >= 200 && status < 305
public setConfig(baseUrl: string, allowInsecure = false) {
this.instantiateHttpClient(baseUrl, allowInsecure)
}
public getCsrfToken(type: 'general' | 'file' = 'general') {
@@ -517,6 +506,25 @@ export class RequestClient implements HttpClient {
return responseToReturn
}
private instantiateHttpClient(baseUrl: string, allowInsecure = false) {
const https = require('https')
if (allowInsecure && https.Agent) {
this.httpClient = axios.create({
baseURL: baseUrl,
httpsAgent: new https.Agent({
rejectUnauthorized: !allowInsecure
})
})
} else {
this.httpClient = axios.create({
baseURL: baseUrl
})
}
this.httpClient.defaults.validateStatus = (status) =>
status >= 200 && status < 305
}
}
export const throwIfError = (response: AxiosResponse) => {