-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import axios, { type AxiosRequestConfig } from 'axios' | ||
import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios' | ||
import defu from 'defu' | ||
|
||
const runtimeConfig = useRuntimeConfig() | ||
let axiosInstance: AxiosInstance | null = null | ||
|
||
export const commonOptions = { | ||
params: { | ||
u: runtimeConfig.env.NAVIDROME_USERNAME, | ||
p: runtimeConfig.env.NAVIDROME_PASSWORD, | ||
v: '1.16.1', | ||
c: 'my-client', | ||
f: 'json' | ||
export const axiosInfo = { | ||
get commonOptions() { | ||
const runtimeConfig = useRuntimeConfig() | ||
|
||
return { | ||
params: { | ||
u: runtimeConfig.env.NAVIDROME_USERNAME, | ||
p: runtimeConfig.env.NAVIDROME_PASSWORD, | ||
v: '1.16.1', | ||
c: 'my-client', | ||
f: 'json' | ||
} | ||
} | ||
}, | ||
|
||
get instance() { | ||
if (axiosInstance) { | ||
return axiosInstance | ||
} | ||
|
||
const runtimeConfig = useRuntimeConfig() | ||
|
||
axiosInstance = axios.create({ | ||
baseURL: runtimeConfig.env.NAVIDROME_API_URL | ||
}) | ||
|
||
return axiosInstance | ||
} | ||
} | ||
|
||
export const axiosInstance = axios.create({ | ||
baseURL: runtimeConfig.env.NAVIDROME_API_URL | ||
}) | ||
|
||
export function mergeOptions(...options: AxiosRequestConfig[]) { | ||
return defu(commonOptions, ...options) | ||
return defu(axiosInfo.commonOptions, ...options) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters