How can I ensure that a custom header (Accept-Content-Language
) is sent with every request, including Inertia manual visits?
Below is the code snippet where I define and set the header:
import axios from 'axios';
const lang = localStorage.getItem('vue_i18n_locale');
if (lang) {
axios.defaults.headers.common['Accept-Content-Language'] = lang;
axios.defaults.headers.common['Accept-Language'] = lang;
}
window.axios = axios;
When trying to make a call like this:
$inertia.post('some-route', { some: data })
I am aware of manually passing the header prop during the visit, but I want this header to be automatically included in all requests throughout the application without needing to add it manually each time.
Is there a way to achieve this auto-inclusion? My searches online have not yielded a solution, so I'm hoping someone here might have some insights.