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

Swagger not working with @elysiajs/cors #110

Open
Ateeb-Khan-97 opened this issue Mar 28, 2024 · 13 comments
Open

Swagger not working with @elysiajs/cors #110

Ateeb-Khan-97 opened this issue Mar 28, 2024 · 13 comments

Comments

@Ateeb-Khan-97
Copy link

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
Copy link
Collaborator

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

@lndgalante
Copy link

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
Copy link
Collaborator

@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
Copy link

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
Copy link
Collaborator

hey appreciate this :) let me investigate 🤔

@marclave
Copy link
Collaborator

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
Copy link
Collaborator

but let me find a proper fix : )

@marclave
Copy link
Collaborator

@lndgalante @Ateeb-Khan-97 found it 😶‍🌫️

#114

feel free to pull and give this a test :)

@lndgalante
Copy link

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

@marclave
Copy link
Collaborator

cool let me merge :)

@Ateeb-Khan-97
Copy link
Author

@marclave Thanks man, appreciate it!

@cholasimmons
Copy link

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

@marclave
Copy link
Collaborator

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

it was fixed in #114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants