refactor(signalwire): add dynamic api base url
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
if (
|
||||
requestConfig.headers &&
|
||||
$.auth.data?.accountSid &&
|
||||
$.auth.data?.authToken
|
||||
) {
|
||||
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
const authData = $.auth.data || {};
|
||||
|
||||
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
if (
|
||||
authData.accountSid &&
|
||||
authData.authToken
|
||||
) {
|
||||
requestConfig.auth = {
|
||||
username: $.auth.data.accountSid as string,
|
||||
password: $.auth.data.authToken as string,
|
||||
username: authData.accountSid as string,
|
||||
password: authData.authToken as string,
|
||||
};
|
||||
}
|
||||
|
||||
if (authData.spaceName) {
|
||||
const serverUrl = `https://${authData.spaceName}.${authData.spaceRegion}signalwire.com`;
|
||||
|
||||
requestConfig.baseURL = serverUrl as string;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user