Skip to content

Commit 6cfcdfc

Browse files
committed
minify json responses and cached data
1 parent 8a79aee commit 6cfcdfc

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const app = new Elysia()
8888
if (!req.ok) {
8989
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
9090
}
91-
const data = await req.text()
91+
const data = JSON.stringify(await req.json())
9292
scoreboardCache.set(store.cacheKey, data)
9393
return data
9494
})
@@ -107,7 +107,7 @@ export const app = new Elysia()
107107
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
108108
}
109109

110-
const data = await req.text()
110+
const data = JSON.stringify(await req.json())
111111
cache.set(store.cacheKey, data)
112112
return data
113113
})
@@ -156,12 +156,9 @@ export const app = new Elysia()
156156
if (!res.ok) {
157157
throw new NotFoundError(JSON.stringify({ message: 'Resource not found' }))
158158
}
159-
const data = await res.text()
160-
161-
// cache data
159+
const data = JSON.stringify(await res.json())
162160
scoreboardCache.set(store.cacheKey, data)
163161
scoreboardCache.set(url, data)
164-
165162
return data
166163
} finally {
167164
semUrl.release()
@@ -176,11 +173,8 @@ export const app = new Elysia()
176173
return cache.get(store.cacheKey)
177174
}
178175
// fetch data
179-
const data = JSON.stringify(await getData({ path, page }))
180-
181-
// cache data
176+
const data = await getData({ path, page })
182177
cache.set(store.cacheKey, data)
183-
184178
return data
185179
})
186180
.listen(3000)

0 commit comments

Comments
 (0)