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

Elysia application does not load swagger documentation if using elysia-helmet lib #147

Open
vitorpldev opened this issue Sep 4, 2024 · 1 comment

Comments

@vitorpldev
Copy link

I'm facing a problem when using swagger() and helmet() together in an Elysia application. When I configure the application as follows:

import Elysia from 'elysia'
import swagger from '@elysiajs/swagger'
import { helmet } from 'elysia-helmet'

const app = new Elysia()
  .use(swagger())
  .use(helmet())
  .get('/root', () => 'Hello World')
  .listen(3333)

Swagger should automatically add a /swagger route to document API routes. However, when using helmet(), the /swagger route does not load correctly; the page is completely blank.

It seems that helmet() is enforcing some security restrictions that prevent Swagger from working as expected. If anyone has experienced this or knows of a solution, I would appreciate your help!

@vastamaki
Copy link

vastamaki commented Sep 29, 2024

You can use something like this to make it work

app.use(
  helmet({
    contentSecurityPolicy: {
      directives: {
        defaultSrc: ["'self'"],
        scriptSrc: [
          "'self'",
          "'unsafe-inline'",
          'unpkg.com',
          'cdn.jsdelivr.net',
        ],
        styleSrc: ["'self'", "'unsafe-inline'", 'unpkg.com'],
        imgSrc: ['data:'],
      },
    },
  })
)

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

2 participants