Socket
Socket
Sign inDemoInstall

@fastify/static

Package Overview
Dependencies
46
Maintainers
20
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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)

8

package.json
{
"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,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc