chore: added logging
This commit is contained in:
parent
c725207173
commit
05562a8a6f
2 changed files with 14 additions and 0 deletions
|
@ -5,6 +5,7 @@ import { ffetch } from '../utils/fetch.ts'
|
||||||
|
|
||||||
const WEBRING_URL = 'https://otomir23.me/webring/5/data'
|
const WEBRING_URL = 'https://otomir23.me/webring/5/data'
|
||||||
const WEBRING_TTL = 1000 * 60 * 60 * 24 // 24 hours
|
const WEBRING_TTL = 1000 * 60 * 60 * 24 // 24 hours
|
||||||
|
const STALE_TTL = 1000 * 60 * 60 * 8 // 8 hours
|
||||||
|
|
||||||
const WebringItem = z.object({
|
const WebringItem = z.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
|
@ -29,4 +30,5 @@ export const webring = new AsyncResource<WebringData>({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
swr: true,
|
swr: true,
|
||||||
|
swrValidator: ({ currentFetchedAt }) => Date.now() - currentFetchedAt < STALE_TTL,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
import { ffetchAddons, ffetchBase } from '@fuman/fetch'
|
import { ffetchAddons, ffetchBase } from '@fuman/fetch'
|
||||||
import { ffetchZodAdapter } from '@fuman/fetch/zod'
|
import { ffetchZodAdapter } from '@fuman/fetch/zod'
|
||||||
|
|
||||||
|
@ -6,6 +7,17 @@ export const ffetch = ffetchBase.extend({
|
||||||
ffetchAddons.parser(ffetchZodAdapter()),
|
ffetchAddons.parser(ffetchZodAdapter()),
|
||||||
ffetchAddons.retry(),
|
ffetchAddons.retry(),
|
||||||
],
|
],
|
||||||
|
middlewares: [
|
||||||
|
async (req, next) => {
|
||||||
|
console.log('[%s] fetch(%s %s)', new Date().toISOString(), req.method, req.url)
|
||||||
|
const start = Date.now()
|
||||||
|
try {
|
||||||
|
return await next(req)
|
||||||
|
} finally {
|
||||||
|
console.log('[%s] fetch(%s %s) done in %sms', new Date().toISOString(), req.method, req.url, Date.now() - start)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'tei.su/1.0',
|
'User-Agent': 'tei.su/1.0',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue