I’ve set up home assistant behind nginx as a reverse proxy for external connections. I’ve been trying to add some additional services behind the same proxy, but under different sub-urls (eg, hass is at https://my-server/ - but i also want to be able to proxy https://my-server/other-service/ to a different app.
I’ve had lots of trouble getting it to work, and couldn’t get my head around it - but finally worked out that it’s the home assistant service worker intercepting the requests. I found an issue on github where @happyleaves had the same problem : https://github.com/home-assistant/home-assistant/issues/3010 (might have saved me a lot of head scratching if I’d found this earlier!)
Having spent so long on this, i didn’t want to give up at this point (and I didn’t want to just disable the service worker, as I presume it’s improving performance) - so I started taking a look at the service_worker.js file, which I think is built using https://github.com/GoogleChrome/sw-precache
I think the problem is due to the fact that this is configured to use a navigateFallback URL if the request isn’t in cache and matches a regex in navigateFallbackWhitelist. The regex is set up to match anything which isn’t in a list of specified values (static|api|local|service_worker.js|manifest.json). As my URLs aren’t in that list, the navigateFallback URL is triggered.
I’ve now added my URL to the regex, recompressed the service_worker.js file, and reloaded the service worker - and my URL is now working correctly and not being intercepted by the service worker.
Now that I’ve figured all this out, it’s not too difficult to modify the file again when I update home assistant - but my feature request is :
- Would it be possible to add a nice configuration parameter somewhere to add custom entries to the regex of URLs for the service worker to ignore? It would be great if I could just configure this once, and then have the same behaviour continue when I upgrade Home Assistant.