elysiajs / elysia-swagger

A plugin for Elysia to auto-generate Swagger page
MIT License
84 stars 45 forks source link

Swagger not working with `@elysiajs/cors` #110

Open Ateeb-Khan-97 opened 6 months ago

Ateeb-Khan-97 commented 6 months ago

When ever I use elysia swagger with elysiajs/cors plugin swagger page doesn't loads and shows a blank page. When i remove this line app.use(cors()); it starts to work.

version of each pakage are here. "elysia": "^1.0.9", "@elysiajs/cors": "^1.0.2" "@elysiajs/swagger": "^1.0.3"

marclave commented 6 months ago

@Ateeb-Khan-97 what is the error you're seeing in the console specifically? :)

lndgalante commented 5 months ago

I have the same issue, just renders a white screen and this are the errors I'm getting over the console

CleanShot 2024-04-12 at 18 03 11@2x

marclave commented 5 months ago

@lndgalante @Ateeb-Khan-97 would you be able to share a minimal repo to reproduce?

I tried to add cors to the examples/index.ts but I wasnt able to hit this error 😭

lndgalante commented 5 months ago

Tried a small codesandbox, and it seems it's related to helmet() in the sandbox at least, https://codesandbox.io/p/devbox/objective-sid-t5pcnk?file=%2Fhttp.ts%3A14%2C1 but locally is the CORS middleware which makes the swagger page go blank

marclave commented 5 months ago

hey appreciate this :) let me investigate πŸ€”

marclave commented 5 months ago

okay so short term fix! this works

new Elysia()
  .use(cors())
  .use(
    helmet({
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "script-src": ["'self'", "https://cdn.jsdelivr.net/"],
        },
      },
    }),
  )
  // .use(rateLimit())
  .use(swagger())
  .get("/", () => "Hello Elysia")
  .listen(3000);
marclave commented 5 months ago

but let me find a proper fix : )

marclave commented 5 months ago

@lndgalante @Ateeb-Khan-97 found it πŸ˜Άβ€πŸŒ«οΈ

https://github.com/elysiajs/elysia-swagger/pull/114

feel free to pull and give this a test :)

lndgalante commented 5 months ago

Thanks for taking care of this one @marclave, it works for me!

marclave commented 5 months ago

cool let me merge :)

Ateeb-Khan-97 commented 5 months ago

@marclave Thanks man, appreciate it!

cholasimmons commented 5 months ago

I'm running Elysia 1.1.5 and still having the helmet/swagger conflict. Your quick fix works though, thanks for that

marclave commented 5 months ago

@cholasimmons we just need a release, I think @SaltyAom is able to do a release this upcoming week ✨

it was fixed in https://github.com/elysiajs/elysia-swagger/pull/114

cholasimmons commented 3 months ago

I think I recall trying it in a later version of Bun and it worked, but now Bun 1.1.18 and Helmet 2.0.0 is taking me back to the same blank Swagger page