Skip to content

Commit 51200c3

Browse files
committed
crazy approach to prevent running into CORS Errors ....
1 parent 2b83b95 commit 51200c3

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This RaspberryMatic / CCU3 addon will allow you to access your HomeMatic devices
1515
All this runs on your RaspberryMatic / CCU3. You will not need any extra hardware.
1616

1717
# Installation
18-
Download the addon: https://github.com/thkl/hap-homematic/raw/master/addon_installer/hap-homematic-0.0.8.tar.gz and install it via system preferences.
18+
Download the addon: https://github.com/thkl/hap-homematic/raw/master/addon_installer/hap-homematic-0.0.9.tar.gz and install it via system preferences.
1919

2020
A little bit later (the addon will install all other needed software) you will have a HomeKit button in your ccu system preference page.
2121

addon_installer/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.8
1+
0.0.9

addon_installer/etc/www/index.html

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1+
<body id="body">
2+
3+
Auto Redirect failed so please use the link for :<br />
4+
<a id="https" href="">HTTPS Version</a><br/>
5+
<a id="http" href="">HTTP Version</a><br/>
6+
7+
</body>
18
<script type="text/javascript">
29
const queryString = window.location.search
10+
// Fill the backup
11+
document.getElementById('https').href='https://' + window.location.host +':9874/' + queryString
12+
document.getElementById('http').href='http://' + window.location.host +':9874/' + queryString
13+
314
// Check if the server responds on https
415
let url = 'https://' + window.location.host +':9874/' + queryString
5-
var request = new XMLHttpRequest();
6-
request.open("HEAD", url);
7-
8-
request.addEventListener('error', (e)=>{
9-
// use the http version
10-
console.log(e)
16+
let img = new Image()
17+
img.onload = function() {
18+
console.log("We should use https");
19+
window.location.href = 'https://' + window.location.host +':9874/' + queryString
20+
}
21+
img.onerror = function() {
22+
// the image has failed
23+
console.log('loading https image failed use http')
1124
window.location.href = 'http://' + window.location.host +':9874/' + queryString
12-
})
13-
14-
request.send();
15-
16-
request.onreadystatechange = function() {
17-
if(this.readyState == this.HEADERS_RECEIVED) {
18-
// call the https page
19-
window.location.href = url
20-
}
2125
}
22-
23-
24-
</script>
26+
img.src = 'https://' + window.location.host +':9874/favicon.ico'
27+
28+
</script>
-7.68 KB
Binary file not shown.
7.77 KB
Binary file not shown.

addon_installer/rc.d/hap-homematic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ HAPROOT=/usr/local/addons/hap-homematic/
55
CONFIG_URL=/addons/hap-homematic/index.html
66
CONFIG_DIR=/usr/local/etc/config
77
PIDFILE=/var/run/hap-homematic.pid
8-
VER=0.0.8
8+
VER=0.0.9
99
PSPID=`ps -o pid,comm,args | awk '{if ($2=="node" && $4 ~ /hap-homematic/){print $1}}'`
1010
PSPID2=`ps -o pid,comm,args | awk '{if ($2=="hap-homematic-c"){print $1}}'`
1111
case "$1" in

0 commit comments

Comments
 (0)