fastify-static
Advanced tools
Comparing version 4.2.0 to 4.2.1
28
index.js
@@ -84,2 +84,8 @@ 'use strict' | ||
if (encodingExt) { | ||
if (pathname.endsWith('/')) { | ||
pathname = findIndexFile(pathname, options.root, options.index) | ||
if (!pathname) { | ||
return reply.callNotFound() | ||
} | ||
} | ||
pathnameForSend = pathname + '.' + encodingExt | ||
@@ -128,2 +134,3 @@ } | ||
if (encodingExt) { | ||
reply.header('content-type', getContentType(pathname)) | ||
reply.header('content-encoding', encodingExt) | ||
@@ -381,2 +388,23 @@ } | ||
function getContentType (path) { | ||
const type = send.mime.lookup(path) | ||
const charset = send.mime.charsets.lookup(type) | ||
if (!charset) { | ||
return type | ||
} | ||
return `${type}; charset=${charset}` | ||
} | ||
function findIndexFile (pathname, root, indexFiles = ['index.html']) { | ||
return indexFiles.find(filename => { | ||
const p = path.join(root, pathname, filename) | ||
try { | ||
const stats = statSync(p) | ||
return !stats.isDirectory() | ||
} catch (e) { | ||
return false | ||
} | ||
}) | ||
} | ||
// Adapted from https://github.com/fastify/fastify-compress/blob/fa5c12a5394285c86d9f438cb39ff44f3d5cde79/index.js#L442 | ||
@@ -383,0 +411,0 @@ function checkEncodingHeaders (headers, checked) { |
{ | ||
"name": "fastify-static", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
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
333023
45
3881