Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable, Optional } from '@nestjs/common';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { readFileSync } from 'fs';

export enum Process {
SYNC_ONCHAIN_TRANSACTIONS = 'SyncOnchainTransactions',
Expand All @@ -22,6 +23,17 @@ export function GetConfig(): Configuration {
return new Configuration();
}

// Reads the live LND TLS certificate from the file pointed to by LIGHTNING_API_CERTIFICATE_PATH.
// If the path is unset, returns undefined (environments without Lightning, e.g. tests, still boot).
// If the path is set but the file is missing/unreadable, readFileSync throws so a broken mount
// surfaces immediately instead of being masked by a stale fallback.
function readCert(): string | undefined {
const path = process.env.LIGHTNING_API_CERTIFICATE_PATH;
if (!path) return undefined;

return readFileSync(path, 'utf8');
}

export class Configuration {
port = process.env.PORT ?? 3000;
environment: Environment = process.env.ENVIRONMENT as Environment;
Expand Down Expand Up @@ -117,7 +129,7 @@ export class Configuration {
wsInvoicesUrl: process.env.LIGHTNING_LND_WS_INVOICES_URL ?? '',
wsPaymentsUrl: process.env.LIGHTNING_LND_WS_PAYMENTS_URL ?? '',
},
certificate: process.env.LIGHTNING_API_CERTIFICATE?.split('<br>').join('\n'),
certificate: readCert(),
lnbitsapi: {
apiUrl: process.env.LIGHTNING_LNBITSAPI_API_URL ?? '',
certificate: process.env.LIGHTNING_LNBITSAPI_CERTIFICATE?.split('<br>').join('\n') ?? '',
Expand Down
Loading