Fix HTTPS emulator (fix #5337)

This commit is contained in:
Anton Tananaev 2024-06-10 06:14:01 -07:00
parent 57598cef5e
commit 8ab0fc98d7

View File

@ -69,15 +69,26 @@ const EmulatorPage = () => {
const handleClick = useCatch(async (latitude, longitude) => {
if (deviceId) {
const params = new URLSearchParams();
params.append('id', devices[deviceId].uniqueId);
params.append('lat', latitude);
params.append('lon', longitude);
const response = await fetch(`http://${window.location.hostname}:5055?${params.toString()}`, {
method: 'GET',
mode: 'no-cors',
});
let response;
if (window.location.protocol === 'https:') {
const formData = new FormData();
formData.append('id', devices[deviceId].uniqueId);
formData.append('lat', latitude);
formData.append('lon', longitude);
response = await fetch(window.location.origin, {
method: 'POST',
body: formData,
});
} else {
const params = new URLSearchParams();
params.append('id', devices[deviceId].uniqueId);
params.append('lat', latitude);
params.append('lon', longitude);
response = await fetch(`http://${window.location.hostname}:5055?${params.toString()}`, {
method: 'POST',
mode: 'no-cors',
});
}
if (!response.ok) {
throw Error(await response.text());
}