Skip to content

Commit

Permalink
minify json responses and cached data
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygd committed Dec 6, 2024
1 parent 8a79aee commit 6cfcdfc
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const app = new Elysia()
if (!req.ok) {
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
}
const data = await req.text()
const data = JSON.stringify(await req.json())
scoreboardCache.set(store.cacheKey, data)
return data
})
Expand All @@ -107,7 +107,7 @@ export const app = new Elysia()
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
}

const data = await req.text()
const data = JSON.stringify(await req.json())
cache.set(store.cacheKey, data)
return data
})
Expand Down Expand Up @@ -156,12 +156,9 @@ export const app = new Elysia()
if (!res.ok) {
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
}
const data = await res.text()

// cache data
const data = JSON.stringify(await res.json())
scoreboardCache.set(store.cacheKey, data)
scoreboardCache.set(url, data)

return data
} finally {
semUrl.release()
Expand All @@ -176,11 +173,8 @@ export const app = new Elysia()
return cache.get(store.cacheKey)
}
// fetch data
const data = JSON.stringify(await getData({ path, page }))

// cache data
const data = await getData({ path, page })
cache.set(store.cacheKey, data)

return data
})
.listen(3000)
Expand Down

0 comments on commit 6cfcdfc

Please sign in to comment.