Skip to content

Commit

Permalink
fix: respect global maxAge option as fallback
Browse files Browse the repository at this point in the history
resolves #179
  • Loading branch information
pi0 committed Oct 17, 2023
1 parent 2c33ece commit 2abe014
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const SUPPORTED_FORMATS = new Set([
export function createIPX(userOptions: IPXOptions): IPX {
const options: IPXOptions = defu(userOptions, {
alias: getEnv<Record<string, string>>("IPX_ALIAS") || {},
maxAge: getEnv<number>("IPX_MAX_AGE") || 300,
maxAge: getEnv<number>("IPX_MAX_AGE") ?? 60 /* 1 minute */,
sharpOptions: {},
} satisfies Omit<IPXOptions, "storage">);

Expand Down Expand Up @@ -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,

Check failure on line 115 in src/ipx.ts

View workflow job for this annotation

GitHub Actions / ci

Prefer `Number.parseInt` over `parseInt`
mtime: sourceMeta.mtime ? new Date(sourceMeta.mtime) : undefined,
} satisfies IPXSourceMeta;
});
Expand Down

0 comments on commit 2abe014

Please sign in to comment.