forked from fastify/fastify-swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (30 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
const fsPromises = require('node:fs/promises')
const path = require('node:path')
const fp = require('fastify-plugin')
const csp = require('./static/csp.json')
async function fastifySwaggerUi (fastify, opts) {
fastify.decorate('swaggerCSP', csp)
// if no logo is provided, read default static logo
let logoContent = opts.logo
if (logoContent == null) {
const bufferLogoContent = await fsPromises.readFile(path.join(__dirname, './static/logo.svg'))
logoContent = { type: 'image/svg+xml', content: bufferLogoContent }
}
await fastify.register(require('./lib/routes'), {
prefix: opts.routePrefix || '/documentation',
uiConfig: opts.uiConfig || {},
initOAuth: opts.initOAuth || {},
hooks: opts.uiHooks,
theme: opts.theme || {},
logo: logoContent,
...opts
})
}
module.exports = fp(fastifySwaggerUi, {
fastify: '4.x',
name: '@fastify/swagger-ui',
dependencies: ['@fastify/swagger']
})
module.exports.default = fastifySwaggerUi
module.exports.fastifySwaggerUi = fastifySwaggerUi