mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-05-15 06:58:50 +02:00
fix: use proper User-Agent for unfurl requests
The default facebookexternalhit UA causes many sites to block or redirect-loop, resulting in timeouts. Switch to a well-identified bot UA that sites handle correctly.
This commit is contained in:
@@ -6,6 +6,7 @@ import { createHash } from "crypto";
|
|||||||
const CACHE_DIR = resolve(import.meta.dirname, "..", ".cache", "unfurl");
|
const CACHE_DIR = resolve(import.meta.dirname, "..", ".cache", "unfurl");
|
||||||
const CACHE_DURATION_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
|
const CACHE_DURATION_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
|
||||||
const FAILURE_CACHE_MS = 24 * 60 * 60 * 1000; // 1 day for failed fetches
|
const FAILURE_CACHE_MS = 24 * 60 * 60 * 1000; // 1 day for failed fetches
|
||||||
|
const USER_AGENT = "Mozilla/5.0 (compatible; Indiekit/1.0; +https://getindiekit.com)";
|
||||||
|
|
||||||
// Concurrency limiter — prevents overwhelming outbound network
|
// Concurrency limiter — prevents overwhelming outbound network
|
||||||
let activeRequests = 0;
|
let activeRequests = 0;
|
||||||
@@ -135,7 +136,10 @@ export default function registerUnfurlShortcode(eleventyConfig) {
|
|||||||
// Not cached — fetch with concurrency limiting
|
// Not cached — fetch with concurrency limiting
|
||||||
const metadata = await throttled(async () => {
|
const metadata = await throttled(async () => {
|
||||||
try {
|
try {
|
||||||
return await unfurl(url, { timeout: 20000 });
|
return await unfurl(url, {
|
||||||
|
timeout: 20000,
|
||||||
|
headers: { "User-Agent": USER_AGENT },
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`[unfurl] Failed to fetch ${url}: ${err.message}`);
|
console.warn(`[unfurl] Failed to fetch ${url}: ${err.message}`);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user