The gateway answered every non-page request without a session with a login redirect, which fetch and EventSource cannot follow across origins, so polls, forms and streams failed with errors that said nothing about the session. It now answers anything that does not ask for text/html with a 401 and a WWW-Authenticate header, and the swarm UI reloads on that 401, from a wrapped fetch (one place for every call) and from a probe after a stream dies. A second reload within ten seconds is skipped so a page that keeps answering 401 cannot loop. The proxy test and the docs follow.
25 lines
939 B
TypeScript
25 lines
939 B
TypeScript
import { render } from "preact";
|
|
import { App } from "./App.js";
|
|
import { installSessionGuard } from "./ui/session/session.js";
|
|
|
|
// Before anything fetches: a 401 that means "log in again" reloads the page.
|
|
installSessionGuard();
|
|
|
|
const root = document.getElementById("root");
|
|
if (root) {
|
|
render(<App />, root);
|
|
}
|
|
|
|
// PWA installability — see sw.js's own top comment for
|
|
// what it does and does not cache. Feature-detected: older browsers
|
|
// without service-worker support just don't get the install affordance,
|
|
// nothing here depends on it existing.
|
|
if ("serviceWorker" in navigator) {
|
|
window.addEventListener("load", () => {
|
|
navigator.serviceWorker.register("/sw.js").catch((err: unknown) => {
|
|
// Never surfaces to the operator — a failed SW registration means
|
|
// "not installable this session," not "the app is broken."
|
|
console.error("swarm-ui: service worker registration failed", err);
|
|
});
|
|
});
|
|
}
|