From 5ab5547bf31402f9bcae5fb4f19faa30023df5c7 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Mon, 10 Nov 2025 06:01:07 -0800 Subject: [PATCH] Adding code comments --- bin/server.js | 3 ++- src/config/env/common.js | 27 +++------------------------ 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/bin/server.js b/bin/server.js index cbc25e1..323db79 100644 --- a/bin/server.js +++ b/bin/server.js @@ -1,5 +1,5 @@ /* - Express server for REST2NOSTR Proxy API. + Express server for psf-bch-api REST API. The architecture of the code follows the Clean Architecture pattern. */ @@ -72,6 +72,7 @@ class Server { allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'] })) + // Wrap all endpoints in x402 middleware. This handles payments for the API calls. if (x402Settings.enabled) { const routes = buildX402Routes(this.config.apiPrefix) const facilitatorOptions = x402Settings.facilitatorUrl diff --git a/src/config/env/common.js b/src/config/env/common.js index 55ddf24..137fdd4 100644 --- a/src/config/env/common.js +++ b/src/config/env/common.js @@ -16,6 +16,7 @@ const pkgInfo = JSON.parse(readFileSync(`${__dirname.toString()}/../../../packag const version = pkgInfo.version +// This function is used to convert the string input of an environment variable to a boolean value. const normalizeBoolean = (value, defaultValue) => { if (value === undefined || value === null || value === '') return defaultValue @@ -25,6 +26,8 @@ const normalizeBoolean = (value, defaultValue) => { return defaultValue } +// By default, the price per API call is 2000 satoshis. +// But the user can override this value by setting the X402_PRICE_SAT environment variable. const parsedPriceSat = Number(process.env.X402_PRICE_SAT) const priceSat = Number.isFinite(parsedPriceSat) && parsedPriceSat > 0 ? parsedPriceSat : 2000 @@ -48,30 +51,6 @@ export default { // Logging level logLevel: process.env.LOG_LEVEL || 'info', - // Nostr relay configuration (array of relay URLs) - nostrRelayUrls: (() => { - // Support NOSTR_RELAY_URLS (plural) as comma-separated string or JSON array - if (process.env.NOSTR_RELAY_URLS) { - try { - // Try parsing as JSON array first - const parsed = JSON.parse(process.env.NOSTR_RELAY_URLS) - if (Array.isArray(parsed)) { - return parsed.filter(url => url && typeof url === 'string') - } - } catch (e) { - // Not JSON, treat as comma-separated string - return process.env.NOSTR_RELAY_URLS.split(',').map(url => url.trim()).filter(url => url.length > 0) - } - } - // Backward compatibility: support NOSTR_RELAY_URL (singular) - if (process.env.NOSTR_RELAY_URL) { - return [process.env.NOSTR_RELAY_URL] - } - - // Default - return ['wss://nostr-relay.psfoundation.info', 'wss://relay.damus.io'] - })(), - // Full node RPC configuration fullNode: { rpcBaseUrl: process.env.RPC_BASEURL || 'http://127.0.0.1:8332',