diff --git a/src/gateway/public-gateway.mjs b/src/gateway/public-gateway.mjs index d3db881..1bd4d2a 100644 --- a/src/gateway/public-gateway.mjs +++ b/src/gateway/public-gateway.mjs @@ -1749,7 +1749,15 @@ const server = http.createServer(async (req, res) => { if (!m) { res.writeHead(400, { "content-type": "text/html" }); return res.end(`usage: ${MOUNT}/./`); } const name = m[1].toLowerCase(); const rest = m[2] || "/"; - return serve(res, name, rest, `${MOUNT}/${name}/`); + // baseHref must point at the CURRENT DIRECTORY, not the site root. + // If we injected `` on every page, then a + // relative link like `../plug-ins/` on a subdirectory page (e.g. + // /bns/theseus.x/extensions/) resolves against the base — landing on + // /bns/plug-ins/, dropping the name. Using the directory of `rest` + // makes `.`, `..`, `foo/`, `../bar/` all resolve as the browser would + // if the site were served from its own origin. + const restDir = rest.replace(/[^/]*$/, "") || "/"; + return serve(res, name, rest, `${MOUNT}/${name}${restDir}`); } catch (e) { res.writeHead(500); res.end("gateway error: " + e.message); } }); server.listen(PORT, "127.0.0.1", () => console.log(`bns public gateway on 127.0.0.1:${PORT} (path ${MOUNT}, subdomain *.${SUB_BASE})`));