split agent into separate file

develop
Thomas Lynch 1 year ago
parent f81f3db53c
commit 81754f1217
  1. 22
      agent.js
  2. 21
      router.js

@ -0,0 +1,22 @@
'use strict';
const https = require('https')
const agentOptions = {
rejectUnauthorized: !process.env.ALLOW_SELF_SIGNED_SSL,
};
if (process.env.PINNED_FP && process.env.CUSTOM_CA_PATH) {
// console.log('Pinned fingerprint:', process.env.PINNED_FP);
// console.log('Private CA file path:', process.env.CUSTOM_CA_PATH);
agentOptions.ca = require('fs').readFileSync(process.env.CUSTOM_CA_PATH);
agentOptions.checkServerIdentity = (host, cert) => {
//TODO: host verification? e.g. tls.checkServerIdentity(host, cert);
// console.log('Checking:', cert.fingerprint256);
if (process.env.PINNED_FP !== cert.fingerprint256) {
return new Error('Certificate not pinned');
}
}
}
module.exports = new https.Agent(agentOptions);

@ -7,26 +7,9 @@ const express = require('express')
, OpenAPIClientAxios = require('openapi-client-axios').default
, { dynamicResponse } = require('./util.js')
, definition = require('./openapi-definition.js')
, https = require('https')
, fetch = require('node-fetch')
, FormData = require('form-data');
const agentOptions = {
rejectUnauthorized: !process.env.ALLOW_SELF_SIGNED_SSL
};
if (process.env.PINNED_FP && process.env.CUSTOM_CA_PATH) {
// console.log('Pinned fingerprint:', process.env.PINNED_FP);
// console.log('Private CA file path:', process.env.CUSTOM_CA_PATH);
agentOptions.ca = require('fs').readFileSync(process.env.CUSTOM_CA_PATH);
agentOptions.checkServerIdentity = (host, cert) => {
//TODO: host verification? e.g. tls.checkServerIdentity(host, cert);
// console.log('Checking:', cert.fingerprint256);
if (process.env.PINNED_FP !== cert.fingerprint256) {
return new Error('Certificate not pinned');
}
}
}
const agent = new https.Agent(agentOptions);
, FormData = require('form-data')
, agent = require('./agent.js');
const testRouter = (server, app) => {

Loading…
Cancel
Save