diff --git a/backend/src/scripts/listRegistryImages.ts b/backend/src/scripts/listRegistryImages.ts index 15bc3333a..f7622f142 100644 --- a/backend/src/scripts/listRegistryImages.ts +++ b/backend/src/scripts/listRegistryImages.ts @@ -3,11 +3,12 @@ import https from 'node:https' import fetch from 'node-fetch' import { getAccessToken } from '../routes/v1/registryAuth.js' +import { getHttpsAgent } from '../services/v2/http.js' import config from '../utils/config.js' import { connectToMongoose, disconnectFromMongoose } from '../utils/database.js' import logger from '../utils/logger.js' -const httpsAgent = new https.Agent({ +const httpsAgent = getHttpsAgent({ rejectUnauthorized: !config.registry.insecure, }) diff --git a/backend/src/services/v2/http.ts b/backend/src/services/v2/http.ts new file mode 100644 index 000000000..b35fc9403 --- /dev/null +++ b/backend/src/services/v2/http.ts @@ -0,0 +1,7 @@ +import https from 'node:https' + +// This function has the same syntax as 'https.Agent', but is centralised throughout +// the application in case it needs to be altered. +export function getHttpsAgent(config?: https.AgentOptions) { + return new https.Agent({ ...config }) +} diff --git a/backend/test/services/http.spec.ts b/backend/test/services/http.spec.ts new file mode 100644 index 000000000..c7dd1234f --- /dev/null +++ b/backend/test/services/http.spec.ts @@ -0,0 +1,11 @@ +import https from 'node:http' + +import { describe, expect, test } from 'vitest' + +import { getHttpsAgent } from '../../src/services/v2/http.js' + +describe('services > http', () => { + test('getHttpsAgent', () => { + expect(getHttpsAgent()).toBeInstanceOf(https.Agent) + }) +})