Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with latest version of Elysia #4

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elysia-compression",
"version": "0.0.3",
"version": "0.0.4",
"description": "Compression plugin for Elysia",
"author": {
"name": "Gusb3ll",
Expand Down Expand Up @@ -32,12 +32,12 @@
"release": "npm run build && npm publish --access public"
},
"devDependencies": {
"bun-types": "0.6.13",
"elysia": "0.5.20",
"eslint": "8.26.0",
"typescript": "5.1.6"
"bun-types": "1.0.3",
"elysia": "0.7.15",
"eslint": "8.50.0",
"typescript": "5.2.2"
},
"peerDependencies": {
"elysia": ">= 0.5.22"
"elysia": ">= 0.7.15"
}
}
}
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ export const compression =
({ type = 'gzip', options }: CompressionOptions = { type: 'gzip' }) =>
(app: Elysia) => {
if (type === 'gzip') {
return app.onAfterHandle(({ set }, res) => {
set.headers['Content-Encoding'] = 'gzip'
const compressed = gzipSync(toBuffer(res), options)

return new Response(compressed, set)
return app.onAfterHandle((context) => {
context.set.headers['Content-Encoding'] = 'gzip';
const compressed = gzipSync(toBuffer(context.response), options);
context.response = new Response(compressed, context as any);
})
} else if (type === 'deflate') {
return app.onAfterHandle(({ set }, res) => {
set.headers['Content-Encoding'] = 'deflate'
const compressed = deflateSync(toBuffer(res), options)
return app.onAfterHandle((context) => {
context.set.headers['Content-Encoding'] = 'deflate';
const compressed = deflateSync(toBuffer(context.response), options);
context.response = new Response(compressed, context as any);

return new Response(compressed, set)
})
} else {
throw new Error('Invalid compression type.')
Expand Down