quetre/utils/getAxiosInstance.js
kareem d16ae48dcb
feat: add support for other languages
Co-authored-by: k0xp00f <d.abdelkarim1404+gmail.com>
2023-01-07 17:22:20 +00:00

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;