fastify-swagger
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "fastify-swagger", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Generate Swagger files automatically for Fastify.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,7 +8,13 @@ 'use strict' | ||
const files = { | ||
html: readFileSync(resolve(__dirname, 'static', 'index.html'), 'utf8'), | ||
css: readFileSync(resolve(__dirname, 'static', 'swagger-ui.css'), 'utf8'), | ||
js: readFileSync(resolve(__dirname, 'static', 'swagger-ui-bundle.js'), 'utf8'), | ||
preset: readFileSync(resolve(__dirname, 'static', 'swagger-ui-standalone-preset.js'), 'utf8') | ||
'index.html': {type: 'text/html'}, | ||
'swagger-ui.css': {type: 'text/css'}, | ||
'swagger-ui.css.map': {type: 'application/json'}, | ||
'swagger-ui-bundle.js': {type: 'application/javascript'}, | ||
'swagger-ui-bundle.js.map': {type: 'application/json'}, | ||
'swagger-ui-standalone-preset.js': {type: 'application/javascript'}, | ||
'swagger-ui-standalone-preset.js.map': {type: 'application/json'} | ||
} | ||
Object.keys(files).forEach(filename => { | ||
files[filename].contents = readFileSync(resolve(__dirname, 'static', filename), 'utf8') | ||
}) | ||
@@ -52,21 +58,10 @@ function fastifySwagger (fastify, opts, next) { | ||
if (!req.params.file) { | ||
return reply.type('text/html').send(files.html) | ||
const file = files['index.html'] | ||
reply.type(file.type).send(file.contents) | ||
} else if (files.hasOwnProperty(req.params.file)) { | ||
const file = files[req.params.file] | ||
reply.type(file.type).send(file.contents) | ||
} else { | ||
return reply.code(404).send(new Error('Not found')) | ||
} | ||
switch (req.params.file) { | ||
case '': | ||
return reply.type('text/html').send(files.html) | ||
case 'swagger-ui.css': | ||
return reply.type('text/css').send(files.css) | ||
case 'swagger-ui-bundle.js': | ||
return reply.type('application/javascript').send(files.js) | ||
case 'swagger-ui-standalone-preset.js': | ||
return reply.type('application/javascript').send(files.preset) | ||
default: | ||
return reply.code(404).send(new Error('Not found')) | ||
} | ||
} | ||
@@ -73,0 +68,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17805741