Skip to content

Commit

Permalink
feat: add number type to refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed May 4, 2024
1 parent 16c1ed2 commit 411f82a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/frog-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ export type RouteOptions<method extends string = string> = Pick<
initial?: Omit<FrameResponse, 'image'> &
(
| {
refreshing: true
image: () => FrameResponse['image']
refreshing: true | number
image: () =>
| Promise<FrameResponse['image']>
| FrameResponse['image']
}
| {
refreshing?: false | undefined
Expand Down Expand Up @@ -434,7 +436,7 @@ export class FrogBase<
`Image handler cannot return an image at ${c.req.path} if there are no query parameters and if \`initial\` property is not set. Either add query parameters, or add \`initial\` property in the third argument of this frame handler.`,
)

const image_ = await (initial.refreshing
const image_ = await (typeof initial.image === 'function'
? initial.image()
: initial.image)

Expand All @@ -452,11 +454,21 @@ export class FrogBase<
const headers_ = new Headers(defaultHeaders).toJSON()
if (headers_['Cache-Control']) return headers_

headers_['Cache-Control'] = 'max-age=0'
headers_['Cache-Control'] = `max-age=${
typeof initial.refreshing === 'number'
? initial.refreshing
: 0
}`
return headers_
})()
: (() => {
return { 'Cache-Control': 'max-age=0' }
return {
'Cache-Control': `max-age=${
typeof initial.refreshing === 'number'
? initial.refreshing
: 0
}`,
}
})()
: defaultHeaders

Expand Down

0 comments on commit 411f82a

Please sign in to comment.