signaltrail / tree / server.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Local Node server (same handler as the Worker). Key: SIGNALTRAIL_KEY_FILE (default: vault path). Ledger in memory.
import http from 'node:http';
import fs from 'node:fs';
import { handle } from './src/app.js';
import { importSigner } from './src/receipt.js';
import { MemoryStore } from './src/store.js';
const rd = (f) => JSON.parse(fs.readFileSync(new URL(f, import.meta.url)));
const signer = await importSigner(JSON.parse(fs.readFileSync(process.env.SIGNALTRAIL_KEY_FILE || '/home/box/crypto-vault/signaltrail-signing-key.json')));
const d = { fetch, signer, store: new MemoryStore(), base: process.env.TOOLS_BASE || 'https://api.youraitools.co', now: () => new Date(), issuer: { url: `http://localhost:${process.env.PORT || 8798}` }, dataset: rd('./data/demo-posts.json'), config: rd('./data/config.default.json'), registry: rd('./data/registry.json'), runThrottleMs: 0 };
http.createServer(async (req, res) => {
  const chunks = []; for await (const c of req) chunks.push(c);
  const r = await handle(new Request(`http://localhost${req.url}`, { method: req.method, headers: req.headers, body: ['GET', 'HEAD'].includes(req.method) ? undefined : Buffer.concat(chunks) }), d);
  res.writeHead(r.status, Object.fromEntries(r.headers)); res.end(Buffer.from(await r.arrayBuffer()));
}).listen(process.env.PORT || 8798, () => console.log(`SignalTrail on http://localhost:${process.env.PORT || 8798}`));

agentgate-source: code mirror on Cloudflare Pages. All repos