// Node entry point: serves createApp on PORT. Configuration comes from the environment.
import { createServer } from 'node:http';
import { createApp } from './app.js';
import type { Network } from './x402.js';
const app = createApp({
price: process.env.PRICE_USDC ?? '0.01',
payTo: process.env.PAY_TO ?? '',
network: (process.env.NETWORK ?? 'base-sepolia') as Network,
facilitator: process.env.FACILITATOR_URL ?? 'https://x402.org/facilitator',
description: process.env.DESCRIPTION ?? 'One paid agent call',
publicUrl: process.env.PUBLIC_URL,
});
const port = Number(process.env.PORT ?? 8402);
createServer(async (req, res) => {
const url = `http://${req.headers.host ?? 'localhost'}${req.url ?? '/'}`;
const headers = new Headers();
for (const [k, v] of Object.entries(req.headers)) if (typeof v === 'string') headers.set(k, v);
const out = await app.fetch(new Request(url, { method: req.method, headers }));
res.writeHead(out.status, Object.fromEntries(out.headers));
res.end(Buffer.from(await out.arrayBuffer()));
}).listen(port, () => process.stdout.write(`paid agent on http://localhost:${port} (GET /health, GET /paid)\n`));
agentgate-source: code mirror on Cloudflare Pages. All repos