From c922ce6e0b67c1fbf9f66eb7330be7343763853b Mon Sep 17 00:00:00 2001 From: Samuel Alarco Date: Mon, 13 May 2024 17:24:36 +0100 Subject: [PATCH] chore: Refactor axios.ts to use axios.getUri for fully qualified URL --- src/client/axios.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/client/axios.ts b/src/client/axios.ts index c3a8358..73a41a6 100644 --- a/src/client/axios.ts +++ b/src/client/axios.ts @@ -11,8 +11,7 @@ import { Wallet, PaymentResult, Store } from '../index'; export function setupL402Interceptor(instance: AxiosInstance, wallet: Wallet, store: Store): void { // Request interceptor to set an authorization header if a token is available instance.interceptors.request.use((config: InternalAxiosRequestConfig) => { - // Combine baseURL and URL into a fully qualified URL if baseURL is specified - const url = config.baseURL ? new URL(config.url ?? '', config.baseURL).toString() : config.url; + const url = axios.getUri(config); // Get the fully qualified URL const method = config.method?.toUpperCase() || 'GET'; // Use 'GET' as the default method // Retrieve the token using the fully qualified URL and HTTP method @@ -40,7 +39,7 @@ export function setupL402Interceptor(instance: AxiosInstance, wallet: Wallet, st if (paymentResult.success) { // Create a new L402 token and store it const l402Token = `${challenge.header_key} ${challenge.macaroon}:${paymentResult.preimage}`; - const url = config.baseURL ? new URL(config.url ?? '', config.baseURL).toString() : config.url; + const url = axios.getUri(config); // Get the fully qualified URL const method = config.method?.toUpperCase() || 'GET'; // Use 'GET' as the default method // Store the new token with the fully qualified URL and method