diff --git a/server/http_server.ts b/server/http_server.ts index 8d3622b9..bde030b6 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -344,6 +344,17 @@ export class HttpServer { response.body = "Not exposed"; return; } + // Handle federated links through a simple redirect, only used for attachments loads with service workers disabled + if (name.startsWith("!")) { + let url = name.slice(1); + if (url.startsWith("localhost")) { + url = `http://${url}`; + } else { + url = `https://${url}`; + } + response.redirect(url); + return; + } try { const fileData = await spacePrimitives.readFile( name, diff --git a/web/open_pages.ts b/web/open_pages.ts index 1a8e75a7..f85cf2d0 100644 --- a/web/open_pages.ts +++ b/web/open_pages.ts @@ -1,5 +1,5 @@ import { Client } from "./client.ts"; -import { EditorSelection, EditorView } from "./deps.ts"; +import { EditorSelection } from "./deps.ts"; class PageState { constructor( diff --git a/web/service_worker.ts b/web/service_worker.ts index 394c937d..f50ea00a 100644 --- a/web/service_worker.ts +++ b/web/service_worker.ts @@ -147,6 +147,16 @@ async function handleLocalFileRequest( }, }, ); + } else if (path.startsWith("!")) { + // Federated URL handling + let url = path.slice(1); + if (url.startsWith("localhost")) { + url = `http://${url}`; + } else { + url = `https://${url}`; + } + console.info("Proxying federated URL", path, "to", url); + return fetch(url, { method: "GET", headers: request.headers }); } else { console.error( "Did not find file in locally synced space",