feat(medusa-js): add axios adapter to config (#6214)
**What** - Adds the ability to pass an Axios adapter through the client's config. **Why** - When using NextJS with the edge runtime for deployment on Cloudflare Pages, for example, Axios does not work. Therefore, it is necessary to pass an adapter like [@vespaiach/axios-fetch-adapter](https://github.com/vespaiach/axios-fetch-adapter). **How** - Receives the **axiosAdapter** in the config and implements it when creating the **axiosClient**. Closes #6133
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import axios, { AxiosError, AxiosInstance, AxiosRequestHeaders } from "axios"
|
||||
import axios, {
|
||||
AxiosAdapter,
|
||||
AxiosError,
|
||||
AxiosInstance,
|
||||
AxiosRequestHeaders,
|
||||
} from "axios"
|
||||
import * as rax from "retry-axios"
|
||||
import { v4 as uuidv4 } from "uuid"
|
||||
|
||||
@@ -18,11 +23,12 @@ export interface Config {
|
||||
apiKey?: string
|
||||
publishableApiKey?: string
|
||||
customHeaders?: Record<string, any>
|
||||
axiosAdapter?: AxiosAdapter
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* Options to pass to requests sent to custom API Routes
|
||||
*/
|
||||
export interface RequestOptions {
|
||||
@@ -180,6 +186,7 @@ class Client {
|
||||
createClient(config: Config): AxiosInstance {
|
||||
const client = axios.create({
|
||||
baseURL: config.baseUrl,
|
||||
adapter: config.axiosAdapter,
|
||||
})
|
||||
|
||||
rax.attach(client)
|
||||
@@ -221,8 +228,8 @@ class Client {
|
||||
options: RequestOptions = {},
|
||||
customHeaders: Record<string, any> = {}
|
||||
): Promise<any> {
|
||||
|
||||
customHeaders = { ...this.config.customHeaders, ...customHeaders }
|
||||
|
||||
customHeaders = { ...this.config.customHeaders, ...customHeaders }
|
||||
|
||||
const reqOpts = {
|
||||
method,
|
||||
|
||||
Reference in New Issue
Block a user