Skip to content

Commit

Permalink
🎉 feat: release 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Apr 24, 2024
1 parent 49b5e67 commit 1633f41
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const staticPlugin = async <Prefix extends string = '/prefix'>(

headers['Etag'] = etag
headers['Cache-Control'] = directive
if (maxAge)
if (maxAge !== null)
headers['Cache-Control'] += `, max-age=${maxAge}`

return new Response(file, {
Expand All @@ -278,7 +278,7 @@ export const staticPlugin = async <Prefix extends string = '/prefix'>(

headers['Etag'] = etag
headers['Cache-Control'] = directive
if (maxAge)
if (maxAge !== null)
headers[
'Cache-Control'
] += `, max-age=${maxAge}`
Expand Down Expand Up @@ -371,7 +371,7 @@ export const staticPlugin = async <Prefix extends string = '/prefix'>(

headers['Etag'] = etag
headers['Cache-Control'] = directive
if (maxAge)
if (maxAge !== null)
headers['Cache-Control'] += `, max-age=${maxAge}`

return new Response(file, {
Expand Down
32 changes: 31 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,37 @@ describe('Static Plugin', () => {

const res = await app.handle(req('/public/takodachi'))

expect(res.headers.get('Cache-Control')).toBe('public, max-age=0')
expect(res.headers.get('Cache-Control')).toBe('public, max-age=86400')
expect(res.status).toBe(200)
})

it('skip Cache-Control header when maxAge is null', async () => {
const app = new Elysia().use(
staticPlugin({
maxAge: null
})
)

await app.modules

const res = await app.handle(req('/public/takodachi.png'))

expect(res.headers.get('Cache-Control')).toBe('public')
expect(res.status).toBe(200)
})

it('set cache directive', async () => {
const app = new Elysia().use(
staticPlugin({
directive: 'private'
})
)

await app.modules

const res = await app.handle(req('/public/takodachi.png'))

expect(res.headers.get('Cache-Control')).toBe('private, max-age=86400')
expect(res.status).toBe(200)
})

Expand Down

0 comments on commit 1633f41

Please sign in to comment.