vk98's picture
Initial backend deployment - Hono proxy + ColPali embedding API
5dfbe50
raw
history blame contribute delete
915 Bytes
import * as fs from 'fs';
import * as https from 'https';
import { config } from '../config';
// Create HTTPS agent with certificate authentication
let httpsAgent: https.Agent | undefined;
if (config.vespaCertPath && config.vespaKeyPath) {
try {
httpsAgent = new https.Agent({
cert: fs.readFileSync(config.vespaCertPath),
key: fs.readFileSync(config.vespaKeyPath),
rejectUnauthorized: false
});
} catch (error) {
console.error('Failed to load Vespa certificates:', error);
}
}
export async function vespaFetch(url: string, options: RequestInit = {}) {
// For Node.js 18+, we need to use undici or node-fetch with agent support
const fetch = globalThis.fetch;
if (httpsAgent) {
// @ts-ignore - agent is not in standard fetch types but works in Node.js
return fetch(url, {
...options,
agent: httpsAgent
});
}
return fetch(url, options);
}