Skip to content

Commit

Permalink
馃幆 feat(config): Custom Endpoint Request Headers (danny-avila#1588)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Jan 19, 2024
1 parent dcfd403 commit fc362f6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/services/Endpoints/custom/initializeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const initializeClient = async ({ req, res, endpointOption }) => {
const CUSTOM_API_KEY = extractEnvVariable(endpointConfig.apiKey);
const CUSTOM_BASE_URL = extractEnvVariable(endpointConfig.baseURL);

let resolvedHeaders = {};
if (endpointConfig.headers && typeof endpointConfig.headers === 'object') {
Object.keys(endpointConfig.headers).forEach((key) => {
resolvedHeaders[key] = extractEnvVariable(endpointConfig.headers[key]);
});
}

if (CUSTOM_API_KEY.match(envVarRegex)) {
throw new Error(`Missing API Key for ${endpoint}.`);
}
Expand All @@ -31,6 +38,7 @@ const initializeClient = async ({ req, res, endpointOption }) => {
}

const customOptions = {
headers: resolvedHeaders,
addParams: endpointConfig.addParams,
dropParams: endpointConfig.dropParams,
titleConvo: endpointConfig.titleConvo,
Expand Down

0 comments on commit fc362f6

Please sign in to comment.