mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-19 18:10:06 +00:00
fix: If the request client has already been instantiated, update config
This commit is contained in:
@@ -917,6 +917,11 @@ export default class SASjs {
|
|||||||
this.sasjsConfig.serverUrl,
|
this.sasjsConfig.serverUrl,
|
||||||
this.sasjsConfig.allowInsecureRequests
|
this.sasjsConfig.allowInsecureRequests
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
this.requestClient.setConfig(
|
||||||
|
this.sasjsConfig.serverUrl,
|
||||||
|
this.sasjsConfig.allowInsecureRequests
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.jobsPath =
|
this.jobsPath =
|
||||||
|
|||||||
@@ -52,25 +52,14 @@ export class RequestClient implements HttpClient {
|
|||||||
|
|
||||||
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
protected csrfToken: CsrfToken = { headerName: '', value: '' }
|
||||||
protected fileUploadCsrfToken: CsrfToken | undefined
|
protected fileUploadCsrfToken: CsrfToken | undefined
|
||||||
protected httpClient: AxiosInstance
|
protected httpClient!: AxiosInstance
|
||||||
|
|
||||||
constructor(protected baseUrl: string, allowInsecure = false) {
|
constructor(protected baseUrl: string, allowInsecure = false) {
|
||||||
const https = require('https')
|
this.instantiateHttpClient(baseUrl, allowInsecure)
|
||||||
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) =>
|
public setConfig(baseUrl: string, allowInsecure = false) {
|
||||||
status >= 200 && status < 305
|
this.instantiateHttpClient(baseUrl, allowInsecure)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
public getCsrfToken(type: 'general' | 'file' = 'general') {
|
||||||
@@ -517,6 +506,25 @@ export class RequestClient implements HttpClient {
|
|||||||
|
|
||||||
return responseToReturn
|
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) => {
|
export const throwIfError = (response: AxiosResponse) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user