Javascript translates https to http in fetch command

Viewed 80

I have a website running https. I'm doing an internal query using javascript and fetch, but the fetch translates the relative url to a http address which is then blocked by the site since it will only accept https. How do I tell fetch to use https? The query url works perfectly if changed from http to https.

I call fetch as follows:

fetch('/desks?date_start=' + date_start + '&date_end=' + date_end).then(function(response) {

The error I get in the browser is:

Mixed Content: The page at 'https://xxx.azurewebsites.net/book' was loaded over HTTPS, but requested an insecure resource 'http://xxx.azurewebsites.net/desks/?date_start=09-03-2021&date_end=09-04-2021'. This request has been blocked; the content must be served over HTTPS.

For debugging I tried specifying the full path as follows:

fetch('location.protocol + '//' + location.hostname + ':' + location.port + '/desks/...

and I put up an alert to make sure the string was build as expected. But I get the exact same error.

It is build using flask and hosted on Azure.

0 Answers
Related