Skip to content

Commit 1705e76

Browse files
committed
chore(express): convert post to get and add logs
TICKET: WP-4376
1 parent 8ca192c commit 1705e76

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

modules/express/src/clientRoutes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,9 @@ export function setupSigningRoutes(app: express.Application, config: Config): vo
17711771
);
17721772
}
17731773

1774-
export function setupEnclavedSigningRoutes(app: express.Application, config: Config): void {
1775-
app.post('/ping/enclavedExpress', parseBody, prepareBitGo(config), promiseWrapper(handlePingEnclavedExpress));
1774+
export function setupEnclavedExpressRoutes(app: express.Application, config: Config): void {
1775+
// Keep the ping endpoint for health checks
1776+
app.get('/ping/enclavedExpress', parseBody, prepareBitGo(config), promiseWrapper(handlePingEnclavedExpress));
17761777
}
17771778

17781779
export function setupLightningSignerNodeRoutes(app: express.Application, config: Config): void {

modules/express/src/config.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EnvironmentName, V1Network } from 'bitgo';
22
import { isNil, isNumber } from 'lodash';
3-
import { readFileSync } from 'fs';
3+
import { readFileSync, existsSync } from 'fs';
44
import 'dotenv/config';
55

66
import { args } from './args';
@@ -170,13 +170,18 @@ function mergeConfigs(...configs: Partial<Config>[]): Config {
170170
enclavedExpressUrl = forceSecureUrl(enclavedExpressUrl);
171171
console.log('Using secure enclaved express URL:', enclavedExpressUrl);
172172
}
173-
const enclavedExpressSSLCertPath = get('enclavedExpressSSLCert');
174-
if (enclavedExpressSSLCertPath) {
173+
const enclavedExpressSSLCertValue = get('enclavedExpressSSLCert');
174+
if (enclavedExpressSSLCertValue) {
175175
try {
176-
enclavedExpressSSLCert = readFileSync(enclavedExpressSSLCertPath, { encoding: 'utf8' });
177-
console.log('Successfully loaded SSL cert from:', enclavedExpressSSLCertPath);
176+
// First try to read it as a file path
177+
enclavedExpressSSLCert = existsSync(enclavedExpressSSLCertValue)
178+
? readFileSync(enclavedExpressSSLCertValue, { encoding: 'utf8' })
179+
: enclavedExpressSSLCertValue; // If not a file, use the value directly
180+
if (existsSync(enclavedExpressSSLCertValue)) {
181+
console.log('Successfully loaded SSL cert from:', enclavedExpressSSLCertValue);
182+
}
178183
} catch (e) {
179-
console.error(`Failed to load enclaved express SSL cert from path: ${enclavedExpressSSLCertPath}`, e);
184+
console.error(`Failed to process enclaved express SSL cert: ${enclavedExpressSSLCertValue}`, e);
180185
}
181186
}
182187
}

modules/express/src/enclavedExpressRoutes/enclavedExpressRoutes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import * as express from 'express';
44
import { retryPromise } from '../retryPromise';
55

66
export async function handlePingEnclavedExpress(req: express.Request) {
7+
console.log('Making enclaved express request with SSL cert to:', req.config?.enclavedExpressUrl);
78
return await retryPromise(
89
() =>
910
superagent
10-
.post(`${req.config?.enclavedExpressUrl}/ping`)
11+
.get(`${req.config?.enclavedExpressUrl}/ping`)
1112
.ca(req.config?.enclavedExpressSSLCert as string)
12-
.send({}),
13+
.send(),
1314
(err, tryCount) => {
1415
debug(`Failed to ping enclavedExpress: ${err.message}`);
1516
}

modules/express/src/expressApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export function setupRoutes(app: express.Application, config: Config): void {
287287
if (config.signerMode) {
288288
clientRoutes.setupSigningRoutes(app, config);
289289
} else if (config.enclavedExpressUrl && config.enclavedExpressSSLCert) {
290-
clientRoutes.setupEnclavedSigningRoutes(app, config);
290+
clientRoutes.setupEnclavedExpressRoutes(app, config);
291291
} else {
292292
if (config.lightningSignerFileSystemPath) {
293293
clientRoutes.setupLightningSignerNodeRoutes(app, config);

modules/express/test/unit/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ describe('Config:', () => {
8383
customrooturi: 'argcustomRootUri',
8484
custombitcoinnetwork: 'argcustomBitcoinNetwork',
8585
externalSignerUrl: 'argexternalSignerUrl',
86+
enclavedExpressUrl: 'argenclavedExpressUrl',
87+
enclavedExpressSSLCert: 'argenclavedExpressSSLCert',
8688
signerMode: 'argsignerMode',
8789
signerFileSystemPath: 'argsignerFileSystemPath',
8890
lightningSignerFileSystemPath: 'arglightningSignerFileSystemPath',
@@ -107,6 +109,8 @@ describe('Config:', () => {
107109
BITGO_CUSTOM_ROOT_URI: 'envcustomRootUri',
108110
BITGO_CUSTOM_BITCOIN_NETWORK: 'envcustomBitcoinNetwork',
109111
BITGO_EXTERNAL_SIGNER_URL: 'envexternalSignerUrl',
112+
BITGO_ENCLAVED_EXPRESS_URL: 'envenclavedExpressUrl',
113+
BITGO_ENCLAVED_EXPRESS_SSL_CERT: 'envenclavedExpressSSLCert',
110114
BITGO_SIGNER_MODE: 'envsignerMode',
111115
BITGO_SIGNER_FILE_SYSTEM_PATH: 'envsignerFileSystemPath',
112116
BITGO_LIGHTNING_SIGNER_FILE_SYSTEM_PATH: 'envlightningSignerFileSystemPath',
@@ -132,6 +136,8 @@ describe('Config:', () => {
132136
customBitcoinNetwork: 'argcustomBitcoinNetwork',
133137
authVersion: 2,
134138
externalSignerUrl: 'https://argexternalSignerUrl',
139+
enclavedExpressUrl: 'https://argenclavedExpressUrl',
140+
enclavedExpressSSLCert: 'argenclavedExpressSSLCert',
135141
signerMode: 'argsignerMode',
136142
signerFileSystemPath: 'argsignerFileSystemPath',
137143
lightningSignerFileSystemPath: 'arglightningSignerFileSystemPath',

0 commit comments

Comments
 (0)