elysia-compression icon indicating copy to clipboard operation
elysia-compression copied to clipboard

Add support for elysia 0.8

Open shrinathprabhu opened this issue 1 year ago • 2 comments

Hey @Gusb3ll , can you add support for elysia 0.8, the current version of elysia-compression is breaking in elysia 0.8

shrinathprabhu avatar Jan 17 '24 08:01 shrinathprabhu

Same issue here, was wondering why cookies were not working and cors failing xD

cupcakearmy avatar Feb 21 '24 19:02 cupcakearmy

If anyone is facing the same issue, here's how I fixed it for mine

import { Elysia } from "elysia";
import { gzipSync } from "bun";

export function compression() {
  return new Elysia({
    name: '@elysiaplugin/compression'
  }).mapResponse(({ response }) => {
    return new Response(
      gzipSync(
        typeof response === "object"
          ? JSON.stringify(response)
          : response.toString()
      )
    );
  });
}

Referenced from Official Elysia Docs: https://elysiajs.com/life-cycle/map-response.html#example

And then you can use it as a plugin middleware for your main app

app.use(compression())

shrinathprabhu avatar Feb 22 '24 03:02 shrinathprabhu