mirror of
https://github.com/sakaljurgis/best-choice.git
synced 2026-07-08 21:47:40 +00:00
Skip auth header when reader API key missing
This commit is contained in:
@@ -26,19 +26,19 @@ export const readUrlMarkdown = async (rawUrl: string): Promise<string> => {
|
|||||||
throw new HttpError(500, 'URL reader requires fetch support but it is unavailable.');
|
throw new HttpError(500, 'URL reader requires fetch support but it is unavailable.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!env.urlReader.apiKey) {
|
|
||||||
throw new HttpError(500, 'URL reader service is not configured.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedTargetUrl = ensureHttpUrl(rawUrl);
|
const normalizedTargetUrl = ensureHttpUrl(rawUrl);
|
||||||
const requestUrl = buildReaderUrl(normalizedTargetUrl);
|
const requestUrl = buildReaderUrl(normalizedTargetUrl);
|
||||||
|
const apiKey = env.urlReader.apiKey?.trim();
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
|
||||||
|
if (apiKey) {
|
||||||
|
headers.Authorization = `Bearer ${apiKey}`;
|
||||||
|
}
|
||||||
|
|
||||||
let response: Awaited<ReturnType<typeof fetch>>;
|
let response: Awaited<ReturnType<typeof fetch>>;
|
||||||
try {
|
try {
|
||||||
response = await fetch(requestUrl, {
|
response = await fetch(requestUrl, {
|
||||||
headers: {
|
headers
|
||||||
Authorization: `Bearer ${env.urlReader.apiKey}`
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
|
|||||||
Reference in New Issue
Block a user