@fastify/static 8.0.3 → 8.1.0
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/.github/dependabot.yml +1 -1
- package/README.md +92 -86
- package/eslint.config.js +1 -0
- package/index.js +4 -3
- package/lib/dirList.js +1 -1
- package/package.json +36 -7
- package/test/content-type.test.js +97 -127
- package/test/dir-list.test.js +264 -369
- package/test/static.test.js +1871 -2360
- package/types/index.d.ts +2 -1
- package/types/index.test-d.ts +22 -21
- package/.eslintrc.json +0 -31
- package/.taprc +0 -2
- package/test/static/shallow/no-link +0 -1
- package/test/static-symbolic-link/dir/symlink +0 -1
package/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
|
|
5
5
|
import { FastifyPluginAsync, FastifyReply, FastifyRequest, RouteOptions } from 'fastify'
|
|
6
|
-
import { Stats } from 'fs'
|
|
6
|
+
import { Stats } from 'node:fs'
|
|
7
7
|
|
|
8
8
|
declare module 'fastify' {
|
|
9
9
|
interface FastifyReply {
|
|
@@ -114,6 +114,7 @@ declare namespace fastifyStatic {
|
|
|
114
114
|
lastModified?: boolean;
|
|
115
115
|
maxAge?: string | number;
|
|
116
116
|
constraints?: RouteOptions['constraints'];
|
|
117
|
+
logLevel?: RouteOptions['logLevel'];
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
export const fastifyStatic: FastifyStaticPlugin
|
package/types/index.test-d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fastify, { FastifyInstance, FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
-
import { Server } from 'http'
|
|
3
|
-
import { Stats } from 'fs'
|
|
2
|
+
import { Server } from 'node:http'
|
|
3
|
+
import { Stats } from 'node:fs'
|
|
4
4
|
import { expectAssignable, expectError, expectType } from 'tsd'
|
|
5
5
|
import * as fastifyStaticStar from '..'
|
|
6
6
|
import fastifyStatic, {
|
|
@@ -62,13 +62,14 @@ const options: FastifyStaticOptions = {
|
|
|
62
62
|
expectType<Stats>(stat)
|
|
63
63
|
},
|
|
64
64
|
preCompressed: false,
|
|
65
|
-
allowedPath: (
|
|
65
|
+
allowedPath: (_pathName: string, _root: string, _request: FastifyRequest) => {
|
|
66
66
|
return true
|
|
67
67
|
},
|
|
68
68
|
constraints: {
|
|
69
69
|
host: /.*\.example\.com/,
|
|
70
70
|
version: '1.0.2'
|
|
71
|
-
}
|
|
71
|
+
},
|
|
72
|
+
logLevel: 'warn'
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
expectError<FastifyStaticOptions>({
|
|
@@ -121,7 +122,7 @@ expectAssignable<FastifyStaticOptions>({
|
|
|
121
122
|
appWithImplicitHttp
|
|
122
123
|
.register(fastifyStatic, options)
|
|
123
124
|
.after(() => {
|
|
124
|
-
appWithImplicitHttp.get('/', (
|
|
125
|
+
appWithImplicitHttp.get('/', (_request, reply) => {
|
|
125
126
|
reply.sendFile('some-file-name')
|
|
126
127
|
})
|
|
127
128
|
})
|
|
@@ -131,23 +132,23 @@ const appWithHttp2 = fastify({ http2: true })
|
|
|
131
132
|
appWithHttp2
|
|
132
133
|
.register(fastifyStatic, options)
|
|
133
134
|
.after(() => {
|
|
134
|
-
appWithHttp2.get('/', (
|
|
135
|
+
appWithHttp2.get('/', (_request, reply) => {
|
|
135
136
|
reply.sendFile('some-file-name')
|
|
136
137
|
})
|
|
137
138
|
|
|
138
|
-
appWithHttp2.get('/download', (
|
|
139
|
+
appWithHttp2.get('/download', (_request, reply) => {
|
|
139
140
|
reply.download('some-file-name')
|
|
140
141
|
})
|
|
141
142
|
|
|
142
|
-
appWithHttp2.get('/download/1', (
|
|
143
|
+
appWithHttp2.get('/download/1', (_request, reply) => {
|
|
143
144
|
reply.download('some-file-name', { maxAge: '2 days' })
|
|
144
145
|
})
|
|
145
146
|
|
|
146
|
-
appWithHttp2.get('/download/2', (
|
|
147
|
+
appWithHttp2.get('/download/2', (_request, reply) => {
|
|
147
148
|
reply.download('some-file-name', 'some-filename', { cacheControl: false, acceptRanges: true })
|
|
148
149
|
})
|
|
149
150
|
|
|
150
|
-
appWithHttp2.get('/download/3', (
|
|
151
|
+
appWithHttp2.get('/download/3', (_request, reply) => {
|
|
151
152
|
reply.download('some-file-name', 'some-filename', { contentType: false })
|
|
152
153
|
})
|
|
153
154
|
})
|
|
@@ -158,35 +159,35 @@ options.root = ['']
|
|
|
158
159
|
multiRootAppWithImplicitHttp
|
|
159
160
|
.register(fastifyStatic, options)
|
|
160
161
|
.after(() => {
|
|
161
|
-
multiRootAppWithImplicitHttp.get('/', (
|
|
162
|
+
multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
|
|
162
163
|
reply.sendFile('some-file-name')
|
|
163
164
|
})
|
|
164
165
|
|
|
165
|
-
multiRootAppWithImplicitHttp.get('/', (
|
|
166
|
+
multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
|
|
166
167
|
reply.sendFile('some-file-name', { cacheControl: false, acceptRanges: true })
|
|
167
168
|
})
|
|
168
169
|
|
|
169
|
-
multiRootAppWithImplicitHttp.get('/', (
|
|
170
|
+
multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
|
|
170
171
|
reply.sendFile('some-file-name', 'some-root-name', { cacheControl: false, acceptRanges: true })
|
|
171
172
|
})
|
|
172
173
|
|
|
173
|
-
multiRootAppWithImplicitHttp.get('/', (
|
|
174
|
+
multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
|
|
174
175
|
reply.sendFile('some-file-name', 'some-root-name-2', { contentType: false })
|
|
175
176
|
})
|
|
176
177
|
|
|
177
|
-
multiRootAppWithImplicitHttp.get('/download', (
|
|
178
|
+
multiRootAppWithImplicitHttp.get('/download', (_request, reply) => {
|
|
178
179
|
reply.download('some-file-name')
|
|
179
180
|
})
|
|
180
181
|
|
|
181
|
-
multiRootAppWithImplicitHttp.get('/download/1', (
|
|
182
|
+
multiRootAppWithImplicitHttp.get('/download/1', (_request, reply) => {
|
|
182
183
|
reply.download('some-file-name', { maxAge: '2 days' })
|
|
183
184
|
})
|
|
184
185
|
|
|
185
|
-
multiRootAppWithImplicitHttp.get('/download/2', (
|
|
186
|
+
multiRootAppWithImplicitHttp.get('/download/2', (_request, reply) => {
|
|
186
187
|
reply.download('some-file-name', 'some-filename', { cacheControl: false, acceptRanges: true })
|
|
187
188
|
})
|
|
188
189
|
|
|
189
|
-
multiRootAppWithImplicitHttp.get('/download/3', (
|
|
190
|
+
multiRootAppWithImplicitHttp.get('/download/3', (_request, reply) => {
|
|
190
191
|
reply.download('some-file-name', 'some-filename', { contentType: false })
|
|
191
192
|
})
|
|
192
193
|
})
|
|
@@ -198,7 +199,7 @@ options.index = false
|
|
|
198
199
|
noIndexApp
|
|
199
200
|
.register(fastifyStatic, options)
|
|
200
201
|
.after(() => {
|
|
201
|
-
noIndexApp.get('/', (
|
|
202
|
+
noIndexApp.get('/', (_request, reply) => {
|
|
202
203
|
reply.send('<h1>fastify-static</h1>')
|
|
203
204
|
})
|
|
204
205
|
})
|
|
@@ -208,7 +209,7 @@ options.root = new URL('')
|
|
|
208
209
|
const URLRootApp = fastify()
|
|
209
210
|
URLRootApp.register(fastifyStatic, options)
|
|
210
211
|
.after(() => {
|
|
211
|
-
URLRootApp.get('/', (
|
|
212
|
+
URLRootApp.get('/', (_request, reply) => {
|
|
212
213
|
reply.send('<h1>fastify-static</h1>')
|
|
213
214
|
})
|
|
214
215
|
})
|
|
@@ -219,7 +220,7 @@ options.index = 'index.html'
|
|
|
219
220
|
defaultIndexApp
|
|
220
221
|
.register(fastifyStatic, options)
|
|
221
222
|
.after(() => {
|
|
222
|
-
defaultIndexApp.get('/', (
|
|
223
|
+
defaultIndexApp.get('/', (_request, reply) => {
|
|
223
224
|
reply.send('<h1>fastify-static</h1>')
|
|
224
225
|
})
|
|
225
226
|
})
|
package/.eslintrc.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": ["@typescript-eslint"],
|
|
3
|
-
"extends": ["eslint:recommended", "standard"],
|
|
4
|
-
"overrides": [
|
|
5
|
-
{
|
|
6
|
-
"files": ["types/*.test-d.ts", "types/*.d.ts"],
|
|
7
|
-
"parser": "@typescript-eslint/parser",
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"project": ["./tsconfig.eslint.json"]
|
|
10
|
-
},
|
|
11
|
-
"extends": [
|
|
12
|
-
"plugin:@typescript-eslint/recommended",
|
|
13
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
|
14
|
-
],
|
|
15
|
-
"rules": {
|
|
16
|
-
"no-use-before-define": "off",
|
|
17
|
-
"@typescript-eslint/no-var-requires": "off",
|
|
18
|
-
"@typescript-eslint/no-unused-vars": "off",
|
|
19
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
20
|
-
"@typescript-eslint/no-floating-promises": "off",
|
|
21
|
-
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
22
|
-
"@typescript-eslint/no-unsafe-argument": "off",
|
|
23
|
-
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
24
|
-
"@typescript-eslint/no-unsafe-call": "off",
|
|
25
|
-
"@typescript-eslint/no-misused-promises": ["error", {
|
|
26
|
-
"checksVoidReturn": false
|
|
27
|
-
}]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
package/.taprc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/none
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
../origin
|