Merge branch 'dev'
This commit is contained in:
commit
ee46f78ac1
|
|
@ -64,7 +64,7 @@ import { splatModule } from "../modules/splat/mod";
|
|||
import { photosModule } from "../modules/photos/mod";
|
||||
import { rsocialsModule } from "../modules/rsocials/mod";
|
||||
import { spaces } from "./spaces";
|
||||
import { renderShell } from "./shell";
|
||||
import { renderShell, renderModuleLanding } from "./shell";
|
||||
import { syncServer } from "./sync-instance";
|
||||
import { loadAllDocs } from "./local-first/doc-persistence";
|
||||
|
||||
|
|
@ -781,14 +781,23 @@ const server = Bun.serve<WSData>({
|
|||
}
|
||||
|
||||
// ── Bare-domain module routes: rspace.online/{moduleId}[/...] ──
|
||||
// Rewrite to /demo/{moduleId}/... so the normal shell renders identically
|
||||
// to how standalone domains (e.g. rtube.online) serve their content.
|
||||
// Exact module path → landing page; sub-paths rewrite to /demo/...
|
||||
if (!subdomain && hostClean.includes("rspace.online")) {
|
||||
const pathSegments = url.pathname.split("/").filter(Boolean);
|
||||
if (pathSegments.length >= 1) {
|
||||
const firstSegment = pathSegments[0];
|
||||
const knownModuleIds = new Set(getAllModules().map((m) => m.id));
|
||||
if (knownModuleIds.has(firstSegment)) {
|
||||
const allModules = getAllModules();
|
||||
const mod = allModules.find((m) => m.id === firstSegment);
|
||||
if (mod) {
|
||||
if (pathSegments.length === 1) {
|
||||
// Exact module path → show landing page
|
||||
const html = renderModuleLanding({
|
||||
module: mod,
|
||||
modules: getModuleInfoList(),
|
||||
});
|
||||
return new Response(html, { headers: { "Content-Type": "text/html" } });
|
||||
}
|
||||
// Sub-paths → rewrite to /demo/{moduleId}/...
|
||||
const rewrittenPath = `/demo${url.pathname}`;
|
||||
const rewrittenUrl = new URL(rewrittenPath + url.search, `http://localhost:${PORT}`);
|
||||
const rewrittenReq = new Request(rewrittenUrl, req);
|
||||
|
|
|
|||
|
|
@ -425,61 +425,6 @@ export interface ModuleLandingOptions {
|
|||
export function renderModuleLanding(opts: ModuleLandingOptions): string {
|
||||
const { module: mod, modules, theme = "dark" } = opts;
|
||||
const moduleListJSON = JSON.stringify(modules);
|
||||
|
||||
// Modules with a standalone domain: embed it in a full-page iframe
|
||||
if (mod.standaloneDomain) {
|
||||
const embedUrl = `https://${escapeAttr(mod.standaloneDomain)}`;
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>${mod.icon}</text></svg>">
|
||||
<title>${escapeHtml(mod.name)} — rSpace</title>
|
||||
<link rel="stylesheet" href="/shell.css">
|
||||
<style>
|
||||
body { margin: 0; overflow: hidden; }
|
||||
.ml-frame-wrap {
|
||||
position: fixed; top: 48px; left: 0; right: 0; bottom: 0;
|
||||
}
|
||||
.ml-frame-wrap iframe {
|
||||
width: 100%; height: 100%; border: none;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
/* Unregister any stale service workers on rspace.online to prevent
|
||||
them from intercepting cross-origin iframe requests */
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.getRegistrations().then(function(regs) {
|
||||
regs.forEach(function(r) { r.unregister(); });
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script defer src="https://rdata.online/collect.js" data-website-id="6ee7917b-0ed7-44cb-a4c8-91037638526b"></script>
|
||||
</head>
|
||||
<body data-theme="${theme}">
|
||||
<header class="rstack-header" data-theme="${theme}">
|
||||
<div class="rstack-header__left">
|
||||
<rstack-app-switcher current="${escapeAttr(mod.id)}"></rstack-app-switcher>
|
||||
</div>
|
||||
<div class="rstack-header__center"></div>
|
||||
<div class="rstack-header__right">
|
||||
<a class="rstack-header__demo-btn" href="${embedUrl}" target="_blank">Open ${escapeHtml(mod.standaloneDomain)}</a>
|
||||
<rstack-identity></rstack-identity>
|
||||
</div>
|
||||
</header>
|
||||
<div class="ml-frame-wrap">
|
||||
<iframe src="${embedUrl}" allow="clipboard-write; fullscreen" sandbox="allow-scripts allow-same-origin allow-popups allow-forms allow-modals"></iframe>
|
||||
</div>
|
||||
<script type="module">
|
||||
import '/shell.js';
|
||||
document.querySelector('rstack-app-switcher')?.setModules(${moduleListJSON});
|
||||
</script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
// Modules without a standalone domain: simple generated landing page
|
||||
const demoUrl = `https://demo.rspace.online/${mod.id}`;
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue