I have a problem with my frontend which is built and mounted to my FastApi application.
The frontend uses a custom axios client, which dynamically loads the baseURL from a config.js file.
No matter what I do, the frontend redirects all API calls to http://ip:port/api/path instead of https://sub.domain.tld/api/path.
Here some snippets of my custom axios client:
export const useApiStore = defineStore('api', () => {
const baseURL = ref(window.config.baseURL || '');
console.log('Initial baseURL:', baseURL.value);
const client = computed(() => {
console.log('Creating axios client with baseURL:', baseURL.value);
return axios.create({
baseURL: baseURL.value,
});
});
const setBaseURL = (url) => {
console.log('Setting new baseURL:', url);
baseURL.value = url;
};
return { baseURL, client, setBaseURL };
});
Load the api.js into main.js:
const app = createApp(App);
const pinia = createPinia();
app.use(pinia);
const apiStore = useApiStore();
apiStore.setBaseURL(window.config.baseURL);
From the vue component make an api_call:
const apiStore = useApiStore();
const response = await apiStore.client.post('/api/v1/start', payload);
This code, at least in my opinion, should work.
I’ve been trying to solve this bug for weeks, but just can’t seem to get it fixed.
The reverse proxy cannot really be at fault here, as NginxProxyManager works with like everything, without any custom config.