agentcomply / tree / server.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Local server: node server.js  (PORT=8787). Reads the signing key from the vault file, never from code.
import http from 'node:http';
import fs from 'node:fs';
import { handle } from './src/app.js';
import { importSigner } from './src/receipt.js';
import { FileStore } from './src/filestore.js';

const KEY_FILE = process.env.AGENTCOMPLY_KEY_FILE || '/home/box/crypto-vault/agentcomply-signing-key.json';
const policy = JSON.parse(fs.readFileSync(new URL('./policy.json', import.meta.url)));
const signer = await importSigner(JSON.parse(fs.readFileSync(KEY_FILE, 'utf8')));
const store = new FileStore(process.env.LEDGER || new URL('./ledger.jsonl', import.meta.url).pathname);
const mode = process.env.MODE === 'paid' && process.env.CREDITS_KEY ? 'paid' : 'preview';
const deps = { fetch, signer, store, policy, mode, creditsKey: process.env.CREDITS_KEY, base: process.env.TOOLS_BASE };
const port = Number(process.env.PORT || 8787);

http.createServer(async (req, res) => {
  const chunks = []; for await (const c of req) chunks.push(c);
  const body = chunks.length ? Buffer.concat(chunks) : undefined;
  const r = await handle(new Request('http://localhost:' + port + req.url, { method: req.method, headers: req.headers, body: ['GET', 'HEAD'].includes(req.method) ? undefined : body }), deps);
  res.writeHead(r.status, Object.fromEntries(r.headers)); res.end(Buffer.from(await r.arrayBuffer()));
}).listen(port, () => console.log(`AgentComply ${mode} mode on http://localhost:${port} (key id ${signer.kid})`));

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