Open bhanukushwah opened 1 year ago
Do you use the helmet plugin? I had to drop elysia helmet plugin to get rid of the error, until the helmet plugin maintainer allow to pass custom config. or at least the plugin options type
Reference this issue in the scalar repo, I'm able to enable helmet together with the swagger plugin:
// helmet.plugin.ts
import { helmet } from 'elysia-helmet'
export const helmetPlugin = helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: [`'self'`, 'unpkg.com'],
styleSrc: [
`'self'`,
`'unsafe-inline'`,
'cdn.jsdelivr.net',
'fonts.googleapis.com',
'unpkg.com',
],
fontSrc: [`'self'`, 'fonts.gstatic.com', 'data:'],
imgSrc: [`'self'`, 'data:', 'cdn.jsdelivr.net'],
scriptSrc: [
`'self'`,
`https: 'unsafe-inline'`,
'cdn.jsdelivr.net',
`'unsafe-eval'`,
],
},
},
})
// main.ts
import { Elysia } from 'elysia'
import swagger from '@elysiajs/swagger'
import { helmetPlugin } from './plugins/helmet.plugin'
const app = new Elysia()
.use(helmetPlugin)
.use(swagger())
.get('/ping', () => 'pong') // Health check
.listen(3000)
console.log(
`🦊 Elysia is running! Access Swagger UI at http://${app.server?.hostname}:${app.server?.port}/swagger`,
)
ERROR : Refused to load the script 'https://unpkg.com/swagger-ui-dist@4.18.2/swagger-ui-bundle.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.