@fastify/static
Advanced tools
Comparing version 6.12.0 to 7.0.0
20
index.js
@@ -7,5 +7,3 @@ 'use strict' | ||
const { statSync } = require('node:fs') | ||
const { promisify } = require('node:util') | ||
const glob = require('glob') | ||
const globPromise = promisify(glob) | ||
const { glob } = require('glob') | ||
const fp = require('fastify-plugin') | ||
@@ -18,5 +16,2 @@ const send = require('@fastify/send') | ||
const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'gu') | ||
const backslashRegex = /\\/gu | ||
const startForwardSlashRegex = /^\//u | ||
const endForwardSlashRegex = /\/$/u | ||
@@ -134,5 +129,6 @@ const doubleForwardSlashRegex = /\/\//gu | ||
} else { | ||
const globPattern = '**/**' | ||
const indexes = opts.index === undefined ? ['index.html'] : [].concat(opts.index) | ||
const indexDirs = new Map() | ||
const routes = new Set() | ||
const globPattern = '**/**' | ||
@@ -142,8 +138,8 @@ const roots = Array.isArray(sendOptions.root) ? sendOptions.root : [sendOptions.root] | ||
const rootPath = roots[i] | ||
const files = await globPromise(path.join(rootPath, globPattern).replace(winSeparatorRegex, path.posix.sep), { nodir: true, dot: opts.serveDotFiles }) | ||
const indexes = opts.index === undefined ? ['index.html'] : [].concat(opts.index) | ||
const posixRootPath = rootPath.split(path.win32.sep).join(path.posix.sep) | ||
const files = await glob(`${posixRootPath}/${globPattern}`, { follow: true, nodir: true, dot: opts.serveDotFiles }) | ||
for (let i = 0; i < files.length; ++i) { | ||
const file = files[i].replace(rootPath.replace(backslashRegex, '/'), '') | ||
.replace(startForwardSlashRegex, '') | ||
const file = files[i].split(path.win32.sep).join(path.posix.sep) | ||
.replace(`${posixRootPath}/`, '') | ||
const route = (prefix + file).replace(doubleForwardSlashRegex, '/') | ||
@@ -157,3 +153,3 @@ | ||
setUpHeadAndGet(routeOpts, route, '/' + file, rootPath) | ||
setUpHeadAndGet(routeOpts, route, `/${file}`, rootPath) | ||
@@ -160,0 +156,0 @@ const key = path.posix.basename(route) |
{ | ||
"name": "@fastify/static", | ||
"version": "6.12.0", | ||
"version": "7.0.0", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "https://github.com/fastify/fastify-static.git" | ||
"url": "git+https://github.com/fastify/fastify-static.git" | ||
}, | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"fastify-plugin": "^4.0.0", | ||
"glob": "^8.0.1", | ||
"glob": "^10.3.4", | ||
"p-limit": "^3.1.0" | ||
@@ -60,3 +60,3 @@ }, | ||
"tap": "^16.0.0", | ||
"tsd": "^0.29.0", | ||
"tsd": "^0.30.0", | ||
"typescript": "^5.1.6" | ||
@@ -63,0 +63,0 @@ }, |
@@ -127,3 +127,3 @@ # @fastify/static | ||
Constraints that will be added to registered routes. See Fastify's documentation for | ||
[route constraints](https://www.fastify.io/docs/latest/Reference/Routes/#constraints). | ||
[route constraints](https://fastify.dev/docs/latest/Reference/Routes/#constraints). | ||
@@ -454,3 +454,3 @@ #### `prefixAvoidTrailingSlash` | ||
request, Fastify's 404 handler will be called. You can set a custom 404 | ||
handler with [`fastify.setNotFoundHandler()`](https://www.fastify.io/docs/latest/Reference/Server/#setnotfoundhandler). | ||
handler with [`fastify.setNotFoundHandler()`](https://fastify.dev/docs/latest/Reference/Server/#setnotfoundhandler). | ||
@@ -480,3 +480,3 @@ When registering `@fastify/static` within an encapsulated context, the `wildcard` option may need to be set to `false` in order to support index resolution and nested not-found-handler: | ||
to Fastify's error handler. You can set a custom error handler with | ||
[`fastify.setErrorHandler()`](https://www.fastify.io/docs/latest/Reference/Server/#seterrorhandler). | ||
[`fastify.setErrorHandler()`](https://fastify.dev/docs/latest/Reference/Server/#seterrorhandler). | ||
@@ -483,0 +483,0 @@ ### Payload `stream.filename` |
@@ -5,3 +5,3 @@ // Definitions by: Jannik <https://github.com/jannikkeye> | ||
import { FastifyPluginAsync, FastifyRequest, RouteOptions } from 'fastify' | ||
import { FastifyPluginAsync, FastifyReply, FastifyRequest, RouteOptions } from 'fastify' | ||
import { Stats } from 'fs' | ||
@@ -23,2 +23,9 @@ | ||
declare namespace fastifyStatic { | ||
export interface SetHeadersResponse { | ||
getHeader: FastifyReply['getHeader']; | ||
setHeader: FastifyReply['header']; | ||
readonly filename: string; | ||
statusCode: number; | ||
} | ||
export interface ExtendedInformation { | ||
@@ -88,3 +95,3 @@ fileCount: number; | ||
schemaHide?: boolean; | ||
setHeaders?: (...args: any[]) => void; | ||
setHeaders?: (res: SetHeadersResponse, path: string, stat: Stats) => void; | ||
redirect?: boolean; | ||
@@ -91,0 +98,0 @@ wildcard?: boolean; |
@@ -1,3 +0,4 @@ | ||
import fastify, { FastifyInstance, FastifyPluginAsync, FastifyRequest } from 'fastify' | ||
import fastify, { FastifyInstance, FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify' | ||
import { Server } from 'http' | ||
import { Stats } from 'fs' | ||
import { expectAssignable, expectError, expectType } from 'tsd' | ||
@@ -52,4 +53,11 @@ import * as fastifyStaticStar from '..' | ||
list: false, | ||
setHeaders: (res: any, pathName: any) => { | ||
res.setHeader('test', pathName) | ||
setHeaders: (res, path, stat) => { | ||
expectType<string>(res.filename) | ||
expectType<number>(res.statusCode) | ||
expectType<ReturnType<FastifyReply['getHeader']>>(res.getHeader('X-Test')) | ||
res.setHeader('X-Test', 'string') | ||
expectType<string>(path) | ||
expectType<Stats>(stat) | ||
}, | ||
@@ -56,0 +64,0 @@ preCompressed: false, |
410838
5304
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.0.1(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.2.1(transitive)
+ Addedglob@10.4.2(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.0(transitive)
+ Addedlru-cache@10.3.0(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedpackage-json-from-dist@1.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@8.1.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@5.1.6(transitive)
- Removedonce@1.4.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedglob@^10.3.4