I have deployed an API server and a client to azure containers. The client makes HTTPS requests to the API URL, This URL is set both at build time and as env variable, following the REACT_APP_API naming convention.
If I go to the API swagger, all the endpoints works.
But I’m facing a problem on the client side, when for some endpoints it works and makes the https request, but for others it makes an http request, which ends up with the error:
The page at 'https://myapp.westus.azurecontainerapps.io/jobs' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint
'http://myapp-api.westus.azurecontainerapps.io/v1/scheduler'.
This request has been blocked; the content must be served over HTTPS.
The jobs page has a button that makes the call to /scheduler, they both share the same apiClient object, like this:
const apiURL: string = "https://myapp-api.westus.azurecontainerapps.io"; // also tried process.env.REACT_APP_API;
const apiClient = axios.create({
baseURL: `${apiURL}/v1`,
headers: {
'Content-Type': 'application/json',
},
});
I’m 100% sure this apiClient is the only one used in all the app, and no hardcoded htpp request is made. I hardcoded for now the HTTPS URL for testing purposes.
For example, in this endpoint it works as expected (and other endpoints as well, post, get, etc):
export async function fetchDatasets(datasetId=null) {
try {
const endpoint = datasetId ? `/datasets/${encodeURIComponent(datasetId)}` : '/datasets';
const response = await apiClient.get(endpoint);
return response.data;
} catch (error) {
console.error('Error fetching datasets:', error);
throw error;
}
}
But here is where I’m having the issue:
export async function createSchedule(data: ScheduleRequest): Promise<any> {
try {
const response = await apiClient.post('/scheduler/', data);
return response.data;
} catch (error) {
console.error('Error creating schedule request:', error);
throw error;
}
}
And also in this one, when jobId is null, it renders the /jobs page and it works, but when jobId is not null, it renders the /jobs/{jobId} page and it fails:
export async function fetchJobs(jobId = null) {
try {
const endpoint = jobId ? `/jobs/${encodeURIComponent(jobId)}` : '/jobs';
const response = await apiClient.get(endpoint);
return response.data;
} catch (error) {
console.error('Error fetching Jobs:', error);
throw error;
}
}
The only difference I can tell, and I’m not sure if it might be the issue, it’s that in the cases that work, the browser url (e.g /datasets) is the same as the API request, but for example, in the scheduling case, it happens that it’s made from the browser page /jobs and requesting /scheduler. But anyways the api and client are deployed to different urls