mirror of
https://github.com/zyachel/quetre.git
synced 2025-04-04 13:37:39 +03:00
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
////////////////////////////////////////////////////////
|
|
// IMPORTS
|
|
////////////////////////////////////////////////////////
|
|
import axios from 'axios';
|
|
|
|
////////////////////////////////////////////////////////
|
|
// FUNCTION
|
|
////////////////////////////////////////////////////////
|
|
/**
|
|
* @description an axios instance having base url already set
|
|
* @param {string} lang language to use. default is english.
|
|
* @returns AxiosInstance
|
|
*/
|
|
const getAxiosInstance = (subdomain = 'www') =>
|
|
axios.create({
|
|
baseURL: `https://${subdomain}.quora.com`,
|
|
// conditionally adding headers to the request config using ES6 spreading and short-circuiting
|
|
headers: {
|
|
...(process.env.AXIOS_USER_AGENT && {
|
|
'User-Agent': process.env.AXIOS_USER_AGENT,
|
|
}),
|
|
...(process.env.ACCEPT && {
|
|
Accept: process.env.ACCEPT,
|
|
}),
|
|
},
|
|
});
|
|
|
|
////////////////////////////////////////////////////////
|
|
// EXPORTS
|
|
////////////////////////////////////////////////////////
|
|
export default getAxiosInstance;
|