diff options
author | Anton Tananaev <anton@traccar.org> | 2024-06-10 06:14:01 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-06-10 06:14:01 -0700 |
commit | 8ab0fc98d713102747f5fd376255ee31be69da97 (patch) | |
tree | c2210919bc51c561f739ae739a7f17db6a89aa48 | |
parent | 57598cef5e2f17b498425780858d1cf816c43037 (diff) | |
download | trackermap-web-8ab0fc98d713102747f5fd376255ee31be69da97.tar.gz trackermap-web-8ab0fc98d713102747f5fd376255ee31be69da97.tar.bz2 trackermap-web-8ab0fc98d713102747f5fd376255ee31be69da97.zip |
Fix HTTPS emulator (fix #5337)
-rw-r--r-- | src/other/EmulatorPage.jsx | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/other/EmulatorPage.jsx b/src/other/EmulatorPage.jsx index 9adc129f..371bac7c 100644 --- a/src/other/EmulatorPage.jsx +++ b/src/other/EmulatorPage.jsx @@ -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()); } |