Adding code comments

This commit is contained in:
Chris Troutner
2025-11-10 06:01:07 -08:00
parent eb57a7c773
commit 5ab5547bf3
2 changed files with 5 additions and 25 deletions
+2 -1
View File
@@ -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. The architecture of the code follows the Clean Architecture pattern.
*/ */
@@ -72,6 +72,7 @@ class Server {
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'] allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With']
})) }))
// Wrap all endpoints in x402 middleware. This handles payments for the API calls.
if (x402Settings.enabled) { if (x402Settings.enabled) {
const routes = buildX402Routes(this.config.apiPrefix) const routes = buildX402Routes(this.config.apiPrefix)
const facilitatorOptions = x402Settings.facilitatorUrl const facilitatorOptions = x402Settings.facilitatorUrl
+3 -24
View File
@@ -16,6 +16,7 @@ const pkgInfo = JSON.parse(readFileSync(`${__dirname.toString()}/../../../packag
const version = pkgInfo.version 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) => { const normalizeBoolean = (value, defaultValue) => {
if (value === undefined || value === null || value === '') return defaultValue if (value === undefined || value === null || value === '') return defaultValue
@@ -25,6 +26,8 @@ const normalizeBoolean = (value, defaultValue) => {
return 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 parsedPriceSat = Number(process.env.X402_PRICE_SAT)
const priceSat = Number.isFinite(parsedPriceSat) && parsedPriceSat > 0 ? parsedPriceSat : 2000 const priceSat = Number.isFinite(parsedPriceSat) && parsedPriceSat > 0 ? parsedPriceSat : 2000
@@ -48,30 +51,6 @@ export default {
// Logging level // Logging level
logLevel: process.env.LOG_LEVEL || 'info', 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 // Full node RPC configuration
fullNode: { fullNode: {
rpcBaseUrl: process.env.RPC_BASEURL || 'http://127.0.0.1:8332', rpcBaseUrl: process.env.RPC_BASEURL || 'http://127.0.0.1:8332',