Drivers code import fails unless CORS Access-Control-Allow-Origin set

A useful documentation enhancement for driver code import into Hubitat might mention that a web server has to implement Cross-Origin Resource Sharing (CORS) before it can serve up a file of code to import from that web server. I spent many hours trying to figure out why wget worked but Import Code from Website using the same URL did not import any code (using Firefox and Opera browsers).

I finally remembered that Firefox has a "console", and upon opening that I found the problem:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at XXX.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

I had to read up on CORS, enable it in my Apache server (a2enmod headers), add the appropriate line to my .htaccess file:

Header set Access-Control-Allow-Origin https://hubitat.local

then restart Apache: systemctl restart apache2

Now both Firefox and Opera can import my driver code from my own web site.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.