@fastify/static 6.4.0 → 6.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +89 -81
- package/index.js +1 -1
- package/package.json +6 -6
- package/test/static.test.js +5 -5
- package/test/types/index.ts +31 -3
package/index.d.ts
CHANGED
|
@@ -8,100 +8,108 @@ import { Stats } from 'fs';
|
|
|
8
8
|
declare module "fastify" {
|
|
9
9
|
interface FastifyReply {
|
|
10
10
|
sendFile(filename: string, rootPath?: string): FastifyReply;
|
|
11
|
-
sendFile(filename: string, options?: SendOptions): FastifyReply;
|
|
12
|
-
sendFile(filename: string, rootPath?: string, options?: SendOptions): FastifyReply;
|
|
13
|
-
download(filepath: string, options?: SendOptions): FastifyReply;
|
|
11
|
+
sendFile(filename: string, options?: fastifyStatic.SendOptions): FastifyReply;
|
|
12
|
+
sendFile(filename: string, rootPath?: string, options?: fastifyStatic.SendOptions): FastifyReply;
|
|
13
|
+
download(filepath: string, options?: fastifyStatic.SendOptions): FastifyReply;
|
|
14
14
|
download(filepath: string, filename?: string): FastifyReply;
|
|
15
|
-
download(filepath: string, filename?: string, options?: SendOptions): FastifyReply;
|
|
15
|
+
download(filepath: string, filename?: string, options?: fastifyStatic.SendOptions): FastifyReply;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
fileCount: number;
|
|
21
|
-
totalFileCount: number;
|
|
22
|
-
folderCount: number;
|
|
23
|
-
totalFolderCount: number;
|
|
24
|
-
totalSize: number;
|
|
25
|
-
lastModified: number;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface ListDir {
|
|
29
|
-
href: string;
|
|
30
|
-
name: string;
|
|
31
|
-
stats: Stats;
|
|
32
|
-
extendedInfo?: ExtendedInformation;
|
|
33
|
-
}
|
|
19
|
+
type FastifyStaticPlugin = FastifyPluginCallback<NonNullable<fastifyStatic.FastifyStaticOptions>>;
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
declare namespace fastifyStatic {
|
|
22
|
+
export interface ExtendedInformation {
|
|
23
|
+
fileCount: number;
|
|
24
|
+
totalFileCount: number;
|
|
25
|
+
folderCount: number;
|
|
26
|
+
totalFolderCount: number;
|
|
27
|
+
totalSize: number;
|
|
28
|
+
lastModified: number;
|
|
29
|
+
}
|
|
40
30
|
|
|
41
|
-
interface
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
export interface ListDir {
|
|
32
|
+
href: string;
|
|
33
|
+
name: string;
|
|
34
|
+
stats: Stats;
|
|
35
|
+
extendedInfo?: ExtendedInformation;
|
|
36
|
+
}
|
|
44
37
|
|
|
45
|
-
interface
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
38
|
+
export interface ListFile {
|
|
39
|
+
href: string;
|
|
40
|
+
name: string;
|
|
41
|
+
stats: Stats;
|
|
42
|
+
}
|
|
50
43
|
|
|
51
|
-
interface
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
render?: ListRender;
|
|
55
|
-
}
|
|
44
|
+
export interface ListRender {
|
|
45
|
+
(dirs: ListDir[], files: ListFile[]): string;
|
|
46
|
+
}
|
|
56
47
|
|
|
57
|
-
interface
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
export interface ListOptions {
|
|
49
|
+
names?: string[];
|
|
50
|
+
extendedFolderInfo?: boolean;
|
|
51
|
+
jsonFormat?: 'names' | 'extended';
|
|
52
|
+
}
|
|
61
53
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
etag?: boolean;
|
|
68
|
-
extensions?: string[];
|
|
69
|
-
immutable?: boolean;
|
|
70
|
-
index?: string[] | string | false;
|
|
71
|
-
lastModified?: boolean;
|
|
72
|
-
maxAge?: string | number;
|
|
73
|
-
}
|
|
54
|
+
export interface ListOptionsJsonFormat extends ListOptions {
|
|
55
|
+
format: 'json';
|
|
56
|
+
// Required when the URL parameter `format=html` exists
|
|
57
|
+
render?: ListRender;
|
|
58
|
+
}
|
|
74
59
|
|
|
75
|
-
export interface
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
serve?: boolean;
|
|
80
|
-
decorateReply?: boolean;
|
|
81
|
-
schemaHide?: boolean;
|
|
82
|
-
setHeaders?: (...args: any[]) => void;
|
|
83
|
-
redirect?: boolean;
|
|
84
|
-
wildcard?: boolean;
|
|
85
|
-
list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat;
|
|
86
|
-
allowedPath?: (pathName: string, root?: string) => boolean;
|
|
87
|
-
/**
|
|
88
|
-
* @description
|
|
89
|
-
* Opt-in to looking for pre-compressed files
|
|
90
|
-
*/
|
|
91
|
-
preCompressed?: boolean;
|
|
60
|
+
export interface ListOptionsHtmlFormat extends ListOptions {
|
|
61
|
+
format: 'html';
|
|
62
|
+
render: ListRender;
|
|
63
|
+
}
|
|
92
64
|
|
|
93
65
|
// Passed on to `send`
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
66
|
+
export interface SendOptions {
|
|
67
|
+
acceptRanges?: boolean;
|
|
68
|
+
cacheControl?: boolean;
|
|
69
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
70
|
+
etag?: boolean;
|
|
71
|
+
extensions?: string[];
|
|
72
|
+
immutable?: boolean;
|
|
73
|
+
index?: string[] | string | false;
|
|
74
|
+
lastModified?: boolean;
|
|
75
|
+
maxAge?: string | number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface FastifyStaticOptions extends SendOptions {
|
|
79
|
+
root: string | string[];
|
|
80
|
+
prefix?: string;
|
|
81
|
+
prefixAvoidTrailingSlash?: boolean;
|
|
82
|
+
serve?: boolean;
|
|
83
|
+
decorateReply?: boolean;
|
|
84
|
+
schemaHide?: boolean;
|
|
85
|
+
setHeaders?: (...args: any[]) => void;
|
|
86
|
+
redirect?: boolean;
|
|
87
|
+
wildcard?: boolean;
|
|
88
|
+
list?: boolean | ListOptionsJsonFormat | ListOptionsHtmlFormat;
|
|
89
|
+
allowedPath?: (pathName: string, root?: string) => boolean;
|
|
90
|
+
/**
|
|
91
|
+
* @description
|
|
92
|
+
* Opt-in to looking for pre-compressed files
|
|
93
|
+
*/
|
|
94
|
+
preCompressed?: boolean;
|
|
95
|
+
|
|
96
|
+
// Passed on to `send`
|
|
97
|
+
acceptRanges?: boolean;
|
|
98
|
+
cacheControl?: boolean;
|
|
99
|
+
dotfiles?: 'allow' | 'deny' | 'ignore';
|
|
100
|
+
etag?: boolean;
|
|
101
|
+
extensions?: string[];
|
|
102
|
+
immutable?: boolean;
|
|
103
|
+
index?: string[] | string | false;
|
|
104
|
+
lastModified?: boolean;
|
|
105
|
+
maxAge?: string | number;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const fastifyStatic: FastifyStaticPlugin;
|
|
109
|
+
|
|
110
|
+
export { fastifyStatic as default };
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
declare function fastifyStatic(...params: Parameters<FastifyStaticPlugin>): ReturnType<FastifyStaticPlugin>;
|
|
106
114
|
|
|
107
|
-
export
|
|
115
|
+
export = fastifyStatic;
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const contentDisposition = require('content-disposition')
|
|
|
9
9
|
const fp = require('fastify-plugin')
|
|
10
10
|
const util = require('util')
|
|
11
11
|
const globPromise = util.promisify(glob)
|
|
12
|
-
const encodingNegotiator = require('
|
|
12
|
+
const encodingNegotiator = require('@fastify/accept-negotiator')
|
|
13
13
|
|
|
14
14
|
const dirList = require('./lib/dirList')
|
|
15
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/static",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.1",
|
|
4
4
|
"description": "Plugin for serving static files as fast as possible.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
"homepage": "https://github.com/fastify/fastify-static",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"content-disposition": "^0.5.3",
|
|
33
|
-
"
|
|
34
|
-
"fastify-plugin": "^
|
|
33
|
+
"@fastify/accept-negotiator": "^1.0.0",
|
|
34
|
+
"fastify-plugin": "^4.0.0",
|
|
35
35
|
"glob": "^8.0.1",
|
|
36
36
|
"p-limit": "^3.1.0",
|
|
37
|
-
"readable-stream": "^
|
|
37
|
+
"readable-stream": "^4.0.0",
|
|
38
38
|
"send": "^0.18.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@fastify/compress": "^6.0.0",
|
|
42
|
-
"@types/node": "^
|
|
42
|
+
"@types/node": "^18.0.0",
|
|
43
43
|
"@typescript-eslint/eslint-plugin": "^2.29.0",
|
|
44
44
|
"@typescript-eslint/parser": "^2.29.0",
|
|
45
45
|
"concat-stream": "^2.0.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"snazzy": "^9.0.0",
|
|
54
54
|
"standard": "^17.0.0",
|
|
55
55
|
"tap": "^16.0.0",
|
|
56
|
-
"tsd": "^0.
|
|
56
|
+
"tsd": "^0.22.0",
|
|
57
57
|
"typescript": "^4.0.2"
|
|
58
58
|
},
|
|
59
59
|
"tsd": {
|
package/test/static.test.js
CHANGED
|
@@ -1642,7 +1642,7 @@ t.test('with fastify-compress', t => {
|
|
|
1642
1642
|
})
|
|
1643
1643
|
})
|
|
1644
1644
|
t.test('register /static/ with schemaHide true', t => {
|
|
1645
|
-
t.plan(
|
|
1645
|
+
t.plan(4)
|
|
1646
1646
|
|
|
1647
1647
|
const pluginOptions = {
|
|
1648
1648
|
root: path.join(__dirname, '/static'),
|
|
@@ -1682,7 +1682,7 @@ t.test('register /static/ with schemaHide true', t => {
|
|
|
1682
1682
|
})
|
|
1683
1683
|
|
|
1684
1684
|
t.test('register /static/ with schemaHide false', t => {
|
|
1685
|
-
t.plan(
|
|
1685
|
+
t.plan(4)
|
|
1686
1686
|
|
|
1687
1687
|
const pluginOptions = {
|
|
1688
1688
|
root: path.join(__dirname, '/static'),
|
|
@@ -1722,7 +1722,7 @@ t.test('register /static/ with schemaHide false', t => {
|
|
|
1722
1722
|
})
|
|
1723
1723
|
|
|
1724
1724
|
t.test('register /static/ without schemaHide', t => {
|
|
1725
|
-
t.plan(
|
|
1725
|
+
t.plan(4)
|
|
1726
1726
|
|
|
1727
1727
|
const pluginOptions = {
|
|
1728
1728
|
root: path.join(__dirname, '/static'),
|
|
@@ -2769,7 +2769,7 @@ t.test('inject support', async (t) => {
|
|
|
2769
2769
|
})
|
|
2770
2770
|
|
|
2771
2771
|
t.test('routes should use custom errorHandler premature stream close', t => {
|
|
2772
|
-
t.plan(
|
|
2772
|
+
t.plan(4)
|
|
2773
2773
|
|
|
2774
2774
|
const pluginOptions = {
|
|
2775
2775
|
root: path.join(__dirname, '/static'),
|
|
@@ -2804,7 +2804,7 @@ t.test('routes should use custom errorHandler premature stream close', t => {
|
|
|
2804
2804
|
})
|
|
2805
2805
|
|
|
2806
2806
|
t.test('routes should fallback to default errorHandler', t => {
|
|
2807
|
-
t.plan(
|
|
2807
|
+
t.plan(4)
|
|
2808
2808
|
|
|
2809
2809
|
const pluginOptions = {
|
|
2810
2810
|
root: path.join(__dirname, '/static'),
|
package/test/types/index.ts
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
|
-
import fastify from 'fastify'
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import fastify, { FastifyInstance, FastifyPluginCallback } from 'fastify'
|
|
2
|
+
import { Server } from 'http';
|
|
3
|
+
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
4
|
+
import * as fastifyStaticStar from '../..';
|
|
5
|
+
import fastifyStatic, {
|
|
6
|
+
FastifyStaticOptions,
|
|
7
|
+
fastifyStatic as fastifyStaticNamed,
|
|
8
|
+
} from '../..'
|
|
9
|
+
|
|
10
|
+
import fastifyStaticCjsImport = require('../..');
|
|
11
|
+
const fastifyStaticCjs = require('../..');
|
|
12
|
+
|
|
13
|
+
const app: FastifyInstance = fastify();
|
|
14
|
+
|
|
15
|
+
app.register(fastifyStatic);
|
|
16
|
+
app.register(fastifyStaticNamed);
|
|
17
|
+
app.register(fastifyStaticCjs);
|
|
18
|
+
app.register(fastifyStaticCjsImport.default);
|
|
19
|
+
app.register(fastifyStaticCjsImport.fastifyStatic);
|
|
20
|
+
app.register(fastifyStaticStar.default);
|
|
21
|
+
app.register(fastifyStaticStar.fastifyStatic);
|
|
22
|
+
|
|
23
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStatic);
|
|
24
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticNamed);
|
|
25
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.default);
|
|
26
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticCjsImport.fastifyStatic);
|
|
27
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(fastifyStaticStar.default);
|
|
28
|
+
expectType<FastifyPluginCallback<FastifyStaticOptions, Server>>(
|
|
29
|
+
fastifyStaticStar.fastifyStatic
|
|
30
|
+
);
|
|
31
|
+
expectType<any>(fastifyStaticCjs);
|
|
4
32
|
|
|
5
33
|
const appWithImplicitHttp = fastify()
|
|
6
34
|
const options: FastifyStaticOptions = {
|