-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnodeA.js
More file actions
65 lines (57 loc) · 1.94 KB
/
nodeA.js
File metadata and controls
65 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import express from "express";
import { Facilitator, createExpressAdapter, startGatewayRegistration } from "x402-open";
import { baseSepolia } from "viem/chains";
import dotenv from "dotenv";
import morgan from "morgan";
dotenv.config();
const app = express();
app.use(express.json());
app.use(morgan("dev"));
// Log all incoming requests with payload
app.use((req, res, next) => {
console.log("\n=== NODE A RECEIVED ===");
console.log(`${req.method} ${req.url}`);
console.log("Headers:", JSON.stringify(req.headers, null, 2));
if (req.body && Object.keys(req.body).length > 0) {
console.log("Body:", JSON.stringify(req.body, null, 2));
}
console.log("======================\n");
// Capture response
const originalSend = res.send;
res.send = function(data) {
console.log("\n=== NODE A SENDING ===");
console.log(`Response to ${req.method} ${req.url}`);
console.log("Status:", res.statusCode);
if (data) {
try {
console.log("Body:", typeof data === 'string' ? data : JSON.stringify(data, null, 2));
} catch (e) {
console.log("Body:", data);
}
}
console.log("======================\n");
return originalSend.call(this, data);
};
next();
});
const facilitator = new Facilitator({
evmPrivateKey: process.env.PRIVATE_KEY,
evmNetworks: [baseSepolia],
svmNetworks: ["solana-devnet"],
});
createExpressAdapter(facilitator, app, "/facilitator");
startGatewayRegistration({
gatewayUrls: process.env.GATEWAY_URLS
? process.env.GATEWAY_URLS.split(",").map((u) => u.trim()).filter(Boolean)
: ["http://localhost:8080/facilitator"],
nodeBaseUrl: process.env.NODE_BASE_URL || "http://localhost:4101/facilitator",
kindsProvider: async () => {
const res = await fetch("http://localhost:4101/facilitator/supported");
const j = await res.json();
return j?.kinds ?? [];
},
debug: true,
});
(async () => {
app.listen(4101, () => console.log("Node A HTTP on 4101"));
})();