From 2abe014383447d6d017c78fc49c1ad21f999fb75 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 17 Oct 2023 23:42:57 +0200 Subject: [PATCH] fix: respect global `maxAge` option as fallback resolves #179 --- src/ipx.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ipx.ts b/src/ipx.ts index 71b2c61..c9b6d5b 100644 --- a/src/ipx.ts +++ b/src/ipx.ts @@ -49,7 +49,7 @@ const SUPPORTED_FORMATS = new Set([ export function createIPX(userOptions: IPXOptions): IPX { const options: IPXOptions = defu(userOptions, { alias: getEnv>("IPX_ALIAS") || {}, - maxAge: getEnv("IPX_MAX_AGE") || 300, + maxAge: getEnv("IPX_MAX_AGE") ?? 60 /* 1 minute */, sharpOptions: {}, } satisfies Omit); @@ -110,11 +110,9 @@ export function createIPX(userOptions: IPXOptions): IPX { message: `Resource not found: ${id}`, }); } + const _maxAge = sourceMeta.maxAge ?? options.maxAge; return { - maxAge: - typeof sourceMeta.maxAge === "string" - ? Number.parseInt(sourceMeta.maxAge) - : sourceMeta.maxAge, + maxAge: typeof _maxAge === "string" ? parseInt(_maxAge) : _maxAge, mtime: sourceMeta.mtime ? new Date(sourceMeta.mtime) : undefined, } satisfies IPXSourceMeta; });