forked from fastify/fastify-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
43 lines (36 loc) · 958 Bytes
/
routes.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
36
37
38
39
40
41
42
43
'use strict'
const fp = require('fastify-plugin')
const path = require('path')
function fastifySwagger (fastify, opts, next) {
fastify.route({
url: '/documentation/json',
method: 'GET',
schema: { hide: true },
handler: function (req, reply) {
reply.send(fastify.swagger())
}
})
fastify.route({
url: '/documentation/yaml',
method: 'GET',
schema: { hide: true },
handler: function (req, reply) {
reply
.type('application/x-yaml')
.send(fastify.swagger({ yaml: true }))
}
})
fastify.route({
url: '/documentation',
method: 'GET',
schema: { hide: true },
handler: (request, reply) => reply.redirect('./documentation/')
})
// serve swagger-ui with the help of fastify-static
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'static'),
prefix: `/documentation/`
})
next()
}
module.exports = fp(fastifySwagger, '>=0.14.0')