Compare commits

...

2 Commits

Author SHA1 Message Date
hobokenchicken 7cdee73542 fix(tauri): unregister and prevent service worker to fix 404 cache routing issues
Release Desktop Apps / build-linux (push) Successful in 3m17s
Release Desktop Apps / build-windows (push) Successful in 3h17m8s
Release Desktop Apps / release (push) Successful in 13s
2026-07-16 13:58:06 -04:00
hobokenchicken e8ba8ffdba fix(tauri): redirect relative fetch and websocket urls to production backend for desktop app
Release Desktop Apps / build-linux (push) Successful in 3m2s
Release Desktop Apps / build-windows (push) Successful in 3h24m0s
Release Desktop Apps / release (push) Successful in 10s
2026-07-16 13:27:33 -04:00
2 changed files with 42 additions and 4 deletions
+13 -4
View File
@@ -60,11 +60,20 @@
<div id="root"></div> <div id="root"></div>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
<script> <script>
// Register service worker // Register service worker (only for web, avoid in Tauri to prevent 404 cache bugs)
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
window.addEventListener('load', () => { if (!('__TAURI_INTERNALS__' in window) && !('__TAURI__' in window)) {
navigator.serviceWorker.register('/sw.js').catch(() => {}); window.addEventListener('load', () => {
}); navigator.serviceWorker.register('/sw.js').catch(() => {});
});
} else {
// In Tauri, aggressively unregister any old service workers that might be causing 404s
navigator.serviceWorker.getRegistrations().then((registrations) => {
for (let registration of registrations) {
registration.unregister();
}
});
}
} }
</script> </script>
</body> </body>
+29
View File
@@ -3,6 +3,35 @@ import { createRoot } from 'react-dom/client';
import './styles/index.css'; import './styles/index.css';
import App from './App.tsx'; import App from './App.tsx';
const isTauri = 'window' in globalThis && '__TAURI_INTERNALS__' in window;
if (isTauri) {
const TARGET = 'https://dumpster.dustin.coffee';
const WS_TARGET = 'wss://dumpster.dustin.coffee';
const originalFetch = window.fetch;
window.fetch = async (input, init) => {
if (typeof input === 'string' && input.startsWith('/')) {
input = TARGET + input;
}
return originalFetch(input, init);
};
const OriginalWebSocket = window.WebSocket;
window.WebSocket = function(url: string | URL, protocols?: string | string[]) {
let urlStr = typeof url === 'string' ? url : url.toString();
if (urlStr.includes('tauri.localhost') || urlStr.includes('tauri://localhost')) {
urlStr = urlStr.replace(/^(wss?|https?|tauri):\/\/tauri\.localhost/, WS_TARGET);
urlStr = urlStr.replace(/^tauri:\/\/localhost/, WS_TARGET);
} else if (urlStr.startsWith('ws://localhost') && isTauri) {
urlStr = urlStr.replace('ws://localhost', WS_TARGET);
} else if (urlStr.startsWith('/')) {
urlStr = WS_TARGET + urlStr;
}
return new OriginalWebSocket(urlStr, protocols);
} as unknown as typeof WebSocket;
window.WebSocket.prototype = OriginalWebSocket.prototype;
}
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<App /> <App />