aboutsummaryrefslogtreecommitdiffstats
path: root/feed/server.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-01 22:48:11 -0700
committerAdam Soltys <[email protected]>2026-10-01 22:48:11 -0700
commit23f18ff13e0a8c612d04727de2ccfadf2d13ff7c (patch)
tree578915726c8b4285d6e0dcaedb6d24049996d773 /feed/server.js
parentc6b279abd5e502ce05c1418797714782356b7707 (diff)
downloadcoinosv3-23f18ff13e0a8c612d04727de2ccfadf2d13ff7c.tar.gz
coinosv3-23f18ff13e0a8c612d04727de2ccfadf2d13ff7c.zip
Shared note links open on the post, with names and faces
The server renders /nevent1 and /note1 pages with the thread inlined (post, root, replies, kind 0s) and Open Graph tags; the client seeds its thread cache from it and opens the thread on the first paint. Without it, a pending frame holds the screen instead of the front door. Profile lookups ask our relays and the profile indexes at once, streamed, instead of one after the other behind five-second waits. A thread opened straight from a link has no Back button. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'feed/server.js')
-rw-r--r--feed/server.js33
1 files changed, 30 insertions, 3 deletions
diff --git a/feed/server.js b/feed/server.js
index 2cf26a1..12ff850 100644
--- a/feed/server.js
+++ b/feed/server.js
@@ -1,12 +1,39 @@
+import { SimplePool } from 'nostr-tools/pool';
import { startFeedCache } from './service.js';
import { snapshotResponse } from './cache.js';
+import { NOTE_PATH, buildThread, createThreadCache, createIndexSource, notePageResponse } from './note-page.js';
const cache = await startFeedCache();
+// SimplePool verifies signatures and matches filters before accepting events.
+const pool = new SimplePool();
+// Every relay's answer, or maxWait — but an ask by id is done the moment
+// every id has turned up, rather than waiting out the slowest relay.
+const query = (relays, filter, maxWait) => new Promise((resolve) => {
+ const got = new Map();
+ let done = false, sub = null;
+ const finish = () => { if (done) return; done = true; try { sub && sub.close(); } catch {} resolve([...got.values()]); };
+ sub = pool.subscribeManyEose(relays, filter, {
+ maxWait,
+ onevent(e) {
+ got.set(e.id, e);
+ if (filter.ids && filter.ids.every((id) => got.has(id))) finish();
+ },
+ onclose: finish,
+ });
+ if (done) try { sub.close(); } catch {}
+});
+const threads = createThreadCache({ build: (ref) => buildThread(ref, query) });
+const index = createIndexSource(process.env.INDEX_URL || 'http://bitcoin-wallet/index.html');
const server = Bun.serve({
hostname: process.env.HOST || '127.0.0.1',
port: Number(process.env.PORT || 8792),
- fetch(req) {
- if (new URL(req.url).pathname !== '/api/feed') return new Response('Not found', { status: 404 });
- return snapshotResponse(cache, req);
+ idleTimeout: 30,
+ async fetch(req) {
+ const path = new URL(req.url).pathname;
+ if (path === '/api/feed') return snapshotResponse(cache, req);
+ if (NOTE_PATH.test(path) && ['GET', 'HEAD'].includes(req.method)) {
+ try { return await notePageResponse(req, { index, threads }); } catch { return new Response('Unavailable', { status: 502 }); }
+ }
+ return new Response('Not found', { status: 404 });
},
});
console.log(`Public feed cache listening on ${server.url}`);