fastify-static
Advanced tools
Comparing version 2.3.4 to 2.4.0
@@ -14,3 +14,3 @@ 'use strict' | ||
function fastifyStatic (fastify, opts, next) { | ||
const error = checkRootPathForErrors(opts.root) | ||
const error = checkRootPathForErrors(fastify, opts.root) | ||
if (error !== undefined) return next(error) | ||
@@ -167,3 +167,3 @@ | ||
function checkRootPathForErrors (rootPath) { | ||
function checkRootPathForErrors (fastify, rootPath) { | ||
if (rootPath === undefined) { | ||
@@ -185,3 +185,4 @@ return new Error('"root" option is required') | ||
if (e.code === 'ENOENT') { | ||
return new Error(`"root" path "${rootPath}" must exist`) | ||
fastify.log.warn(`"root" path "${rootPath}" must exist`) | ||
return | ||
} | ||
@@ -188,0 +189,0 @@ |
{ | ||
"name": "fastify-static", | ||
"version": "2.3.4", | ||
"version": "2.4.0", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"@types/node": "^10.12.27", | ||
"concat-stream": "^2.0.0", | ||
"coveralls": "^3.0.3", | ||
@@ -42,0 +43,0 @@ "eslint-plugin-typescript": "^0.14.0", |
@@ -11,2 +11,4 @@ 'use strict' | ||
const compress = require('fastify-compress') | ||
const concat = require('concat-stream') | ||
const pino = require('pino') | ||
@@ -596,10 +598,18 @@ const fastifyStatic = require('../') | ||
t.test('root not found error', t => { | ||
t.plan(1) | ||
t.test('root not found warning', t => { | ||
t.plan(2) | ||
const rootPath = path.join(__dirname, 'does-not-exist') | ||
const pluginOptions = { root: rootPath } | ||
const fastify = Fastify({ logger: false }) | ||
const destination = concat(data => { | ||
t.equal(JSON.parse(data).msg, `"root" path "${rootPath}" must exist`) | ||
}) | ||
const logger = pino({ | ||
level: 'warn' | ||
}, destination) | ||
const fastify = Fastify({ logger: logger }) | ||
fastify.register(fastifyStatic, pluginOptions) | ||
fastify.listen(0, err => { | ||
t.equal(err.message, `"root" path "${rootPath}" must exist`) | ||
t.error(err) | ||
fastify.server.unref() | ||
destination.end() | ||
}) | ||
@@ -678,3 +688,3 @@ }) | ||
t.test('errors', t => { | ||
t.plan(6) | ||
t.plan(5) | ||
@@ -711,12 +721,2 @@ t.test('no root', t => { | ||
t.test('root doesn\'t exist', t => { | ||
t.plan(1) | ||
const pluginOptions = { root: path.join(__dirname, 'foo', 'bar') } | ||
const fastify = Fastify({ logger: false }) | ||
fastify.register(fastifyStatic, pluginOptions) | ||
.ready(err => { | ||
t.equal(err.constructor, Error) | ||
}) | ||
}) | ||
t.test('root is not a directory', t => { | ||
@@ -723,0 +723,0 @@ t.plan(1) |
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
62942
1639
14