Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor axios.ts to use axios.getUri for fully qualified URL #9

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/client/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>) => {
// 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
Expand Down Expand Up @@ -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
Expand Down
Loading