fix: loggers
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import type { CollectionAfterChangeHook } from 'payload';
|
||||
import { logger as payloadLogger } from 'payload';
|
||||
|
||||
const TRIGGERING = new Set(['articles', 'authors', 'categories', 'editions', 'tags']);
|
||||
|
||||
const log = {
|
||||
info: (msg: string) => console.log(`[revalidate] ${msg}`),
|
||||
warn: (msg: string) => console.warn(`[revalidate] ${msg}`),
|
||||
};
|
||||
|
||||
export const revalidateAstro: CollectionAfterChangeHook = async ({ doc, operation, collection }) => {
|
||||
if (!TRIGGERING.has(collection.slug)) return doc;
|
||||
if (process.env.ASTRO_REVALIDATE_URL && process.env.ASTRO_REVALIDATE_TOKEN) {
|
||||
@@ -11,9 +15,9 @@ export const revalidateAstro: CollectionAfterChangeHook = async ({ doc, operatio
|
||||
process.env.ASTRO_REVALIDATE_TOKEN,
|
||||
)}&collection=${collection.slug}&op=${operation}`;
|
||||
const res = await fetch(url, { method: 'POST' });
|
||||
payloadLogger.info(`Revalidate ${collection.slug} ${operation}: ${res.status}`);
|
||||
log.info(`${collection.slug} ${operation} -> ${res.status}`);
|
||||
} catch (e) {
|
||||
payloadLogger.warn(`Revalidate failed: ${(e as Error).message}`);
|
||||
log.warn(`failed: ${(e as Error).message}`);
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
|
||||
Reference in New Issue
Block a user