Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions data/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@
"group": "hosting",
"summary": "mint a short link on the pit — /f/<code> follows to your url"
},
{
"name": "deploy",
"aliases": [],
"group": "hosting",
"summary": "upload a folder to your Moshpit server — it opens at <name> and <name>.pit.world"
},
{
"name": "games",
"aliases": [
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"check": "bun scripts/sync-commands.mjs --check"
},
"dependencies": {
"@profullstack/footer": "latest",
"express": "5.1.0"
},
"packageManager": "bun@1.4.0"
Expand Down
18 changes: 13 additions & 5 deletions src/server.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import { randomBytes } from 'node:crypto';
import { footerHtml } from '@profullstack/footer';
import { readFileSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -76,12 +77,19 @@ export function createApp() {
res.json({ status: 'ok', version: VERSION, commands: COMMANDS.commands.length }),
);

// The pit.world global footer, fetched server-side (cached 1 h, served stale
// or as nothing when pit.world is slow or down) into the <!--pit-footer-->
// slot every page's foot() leaves. Its <style> gets this response's nonce.
// Two footers fill the slots every page's foot() leaves, both server-side:
// <!--pfs-footer--> gets the shared Profullstack footer (webring + copyright)
// from @profullstack/footer's @latest template (the ring verifier reads raw
// HTML), and <!--pit-footer--> the pit.world global footer (cached 1 h,
// served stale or as nothing when pit.world is slow or down), last in <body>.
// Both inline <style>s get this response's nonce.
const withFooter = async (res, body) => {
const snippet = (await pitFooter()).replace(/<style>/g, `<style nonce="${res.locals.nonce}">`);
return body.replace('<!--pit-footer-->', () => snippet);
const [ring, pit] = await Promise.all([
footerHtml({ site: 'https://moshcode.sh/', nonce: res.locals.nonce }),
pitFooter(),
]);
const snippet = pit.replace(/<style>/g, `<style nonce="${res.locals.nonce}">`);
return body.replace('<!--pfs-footer-->', () => ring).replace('<!--pit-footer-->', () => snippet);
};

const html = async (res, body) =>
Expand Down
1 change: 1 addition & 0 deletions src/site.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function foot() {
<nav aria-label="Footer">${FOOTER_LINKS.map((l) => `<a href="${esc(l.href)}">${esc(l.label)}</a>`).join('')}</nav>
</div>
</footer>
<!--pfs-footer-->
<script src="/app.js" defer></script>
<!--pit-footer-->
</body>
Expand Down
7 changes: 7 additions & 0 deletions test/site.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,10 @@ test('every public page carries exactly one CrawlProof ad frame, allowed by the
assert.match(res.headers.get('content-security-policy'), /frame-src https:\/\/crawlproof\.com/);
}
});

test('home page server-renders the Profullstack webring row', async () => {
const res = await get('/');
// The ring verifier reads raw HTML and never runs script.
assert.match(res.body, /rssamplifier\.com\/ring\/profullstack/);
assert.doesNotMatch(res.body, /<!--pfs-footer-->/);
});
Loading