@fastify/static 7.0.4 → 8.0.0-pre.fv5.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/.github/workflows/ci.yml +1 -1
- package/README.md +3 -3
- package/index.js +127 -149
- package/lib/dirList.js +3 -3
- package/package.json +21 -22
- package/test/dir-list.test.js +30 -2
- package/test/static.test.js +4 -4
package/.github/workflows/ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -477,13 +477,13 @@ If an error occurs while trying to send a file, the error will be passed
|
|
|
477
477
|
to Fastify's error handler. You can set a custom error handler with
|
|
478
478
|
[`fastify.setErrorHandler()`](https://fastify.dev/docs/latest/Reference/Server/#seterrorhandler).
|
|
479
479
|
|
|
480
|
-
### Payload `stream.
|
|
480
|
+
### Payload `stream.path`
|
|
481
481
|
|
|
482
|
-
If you need to access the
|
|
482
|
+
If you need to access the file path inside the `onSend` hook, you can use `payload.path`.
|
|
483
483
|
|
|
484
484
|
```js
|
|
485
485
|
fastify.addHook('onSend', function (req, reply, payload, next) {
|
|
486
|
-
console.log(payload.
|
|
486
|
+
console.log(payload.path)
|
|
487
487
|
next()
|
|
488
488
|
})
|
|
489
489
|
```
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { PassThrough } = require('node:stream')
|
|
4
3
|
const path = require('node:path')
|
|
5
4
|
const { fileURLToPath } = require('node:url')
|
|
6
5
|
const { statSync } = require('node:fs')
|
|
@@ -121,7 +120,7 @@ async function fastifyStatic (fastify, opts) {
|
|
|
121
120
|
})
|
|
122
121
|
if (opts.redirect === true && prefix !== opts.prefix) {
|
|
123
122
|
fastify.get(opts.prefix, routeOpts, (req, reply) => {
|
|
124
|
-
reply.redirect(
|
|
123
|
+
reply.redirect(getRedirectUrl(req.raw.url), 301)
|
|
125
124
|
})
|
|
126
125
|
}
|
|
127
126
|
} else {
|
|
@@ -170,7 +169,7 @@ async function fastifyStatic (fastify, opts) {
|
|
|
170
169
|
|
|
171
170
|
const allowedPath = opts.allowedPath
|
|
172
171
|
|
|
173
|
-
function pumpSendToReply (
|
|
172
|
+
async function pumpSendToReply (
|
|
174
173
|
request,
|
|
175
174
|
reply,
|
|
176
175
|
pathname,
|
|
@@ -222,164 +221,148 @@ async function fastifyStatic (fastify, opts) {
|
|
|
222
221
|
}
|
|
223
222
|
|
|
224
223
|
// `send(..., path, ...)` will URI-decode path so we pass an encoded path here
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
224
|
+
const {
|
|
225
|
+
statusCode,
|
|
226
|
+
headers,
|
|
227
|
+
stream,
|
|
228
|
+
type,
|
|
229
|
+
metadata
|
|
230
|
+
} = await send(request.raw, encodeURI(pathnameForSend), options)
|
|
231
|
+
switch (type) {
|
|
232
|
+
case 'directory': {
|
|
233
|
+
const path = metadata.path
|
|
234
|
+
if (opts.list) {
|
|
235
|
+
await dirList.send({
|
|
236
|
+
reply,
|
|
237
|
+
dir: path,
|
|
238
|
+
options: opts.list,
|
|
239
|
+
route: pathname,
|
|
240
|
+
prefix,
|
|
241
|
+
dotfiles: opts.dotfiles
|
|
242
|
+
}).catch((err) => reply.send(err))
|
|
236
243
|
}
|
|
237
|
-
cb()
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
244
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
+
if (opts.redirect === true) {
|
|
246
|
+
try {
|
|
247
|
+
reply.redirect(getRedirectUrl(request.raw.url), 301)
|
|
248
|
+
} /* c8 ignore start */ catch (error) {
|
|
249
|
+
// the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
|
|
250
|
+
await reply.send(error)
|
|
251
|
+
} /* c8 ignore stop */
|
|
252
|
+
} else {
|
|
253
|
+
// if is a directory path without a trailing slash, and has an index file, reply as if it has a trailing slash
|
|
254
|
+
if (!pathname.endsWith('/') && findIndexFile(pathname, options.root, options.index)) {
|
|
255
|
+
return pumpSendToReply(
|
|
256
|
+
request,
|
|
257
|
+
reply,
|
|
258
|
+
pathname + '/',
|
|
259
|
+
rootPath,
|
|
260
|
+
undefined,
|
|
261
|
+
undefined,
|
|
262
|
+
checkedEncodings
|
|
263
|
+
)
|
|
264
|
+
}
|
|
245
265
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
Object.defineProperty(wrap, 'statusCode', {
|
|
252
|
-
get () {
|
|
253
|
-
return reply.raw.statusCode
|
|
254
|
-
},
|
|
255
|
-
set (code) {
|
|
256
|
-
reply.code(code)
|
|
266
|
+
reply.callNotFound()
|
|
267
|
+
}
|
|
268
|
+
break
|
|
257
269
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
270
|
+
case 'error': {
|
|
271
|
+
if (
|
|
272
|
+
statusCode === 403 &&
|
|
273
|
+
(!options.index || !options.index.length) &&
|
|
274
|
+
pathnameForSend[pathnameForSend.length - 1] === '/'
|
|
275
|
+
) {
|
|
276
|
+
if (opts.list) {
|
|
277
|
+
await dirList.send({
|
|
278
|
+
reply,
|
|
279
|
+
dir: dirList.path(opts.root, pathname),
|
|
280
|
+
options: opts.list,
|
|
281
|
+
route: pathname,
|
|
282
|
+
prefix,
|
|
283
|
+
dotfiles: opts.dotfiles
|
|
284
|
+
}).catch((err) => reply.send(err))
|
|
285
|
+
}
|
|
267
286
|
}
|
|
268
|
-
reply.send(wrap)
|
|
269
|
-
})
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (setHeaders !== undefined) {
|
|
273
|
-
stream.on('headers', setHeaders)
|
|
274
|
-
}
|
|
275
287
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
if (metadata.error.code === 'ENOENT') {
|
|
289
|
+
// when preCompress is enabled and the path is a directory without a trailing slash
|
|
290
|
+
if (opts.preCompressed && encoding) {
|
|
291
|
+
const indexPathname = findIndexFile(pathname, options.root, options.index)
|
|
292
|
+
if (indexPathname) {
|
|
293
|
+
return pumpSendToReply(
|
|
294
|
+
request,
|
|
295
|
+
reply,
|
|
296
|
+
pathname + '/',
|
|
297
|
+
rootPath,
|
|
298
|
+
undefined,
|
|
299
|
+
undefined,
|
|
300
|
+
checkedEncodings
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
288
304
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
request,
|
|
302
|
-
reply,
|
|
303
|
-
pathname + '/',
|
|
304
|
-
rootPath,
|
|
305
|
-
undefined,
|
|
306
|
-
undefined,
|
|
307
|
-
checkedEncodings
|
|
308
|
-
)
|
|
309
|
-
}
|
|
305
|
+
// if file exists, send real file, otherwise send dir list if name match
|
|
306
|
+
if (opts.list && dirList.handle(pathname, opts.list)) {
|
|
307
|
+
await dirList.send({
|
|
308
|
+
reply,
|
|
309
|
+
dir: dirList.path(opts.root, pathname),
|
|
310
|
+
options: opts.list,
|
|
311
|
+
route: pathname,
|
|
312
|
+
prefix,
|
|
313
|
+
dotfiles: opts.dotfiles
|
|
314
|
+
}).catch((err) => reply.send(err))
|
|
315
|
+
return
|
|
316
|
+
}
|
|
310
317
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
318
|
+
// root paths left to try?
|
|
319
|
+
if (Array.isArray(rootPath) && rootPathOffset < (rootPath.length - 1)) {
|
|
320
|
+
return pumpSendToReply(request, reply, pathname, rootPath, rootPathOffset + 1)
|
|
321
|
+
}
|
|
314
322
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// when preCompress is enabled and the path is a directory without a trailing slash
|
|
318
|
-
if (opts.preCompressed && encoding) {
|
|
319
|
-
const indexPathname = findIndexFile(pathname, options.root, options.index)
|
|
320
|
-
if (indexPathname) {
|
|
323
|
+
if (opts.preCompressed && !checkedEncodings.has(encoding)) {
|
|
324
|
+
checkedEncodings.add(encoding)
|
|
321
325
|
return pumpSendToReply(
|
|
322
326
|
request,
|
|
323
327
|
reply,
|
|
324
|
-
|
|
328
|
+
pathnameOrig,
|
|
325
329
|
rootPath,
|
|
326
|
-
|
|
330
|
+
rootPathOffset,
|
|
327
331
|
undefined,
|
|
328
332
|
checkedEncodings
|
|
329
333
|
)
|
|
330
334
|
}
|
|
331
|
-
}
|
|
332
335
|
|
|
333
|
-
|
|
334
|
-
if (opts.list && dirList.handle(pathname, opts.list)) {
|
|
335
|
-
dirList.send({
|
|
336
|
-
reply,
|
|
337
|
-
dir: dirList.path(opts.root, pathname),
|
|
338
|
-
options: opts.list,
|
|
339
|
-
route: pathname,
|
|
340
|
-
prefix,
|
|
341
|
-
dotfiles: opts.dotfiles
|
|
342
|
-
}).catch((err) => reply.send(err))
|
|
343
|
-
return
|
|
336
|
+
return reply.callNotFound()
|
|
344
337
|
}
|
|
345
338
|
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
339
|
+
// The `send` library terminates the request with a 404 if the requested
|
|
340
|
+
// path contains a dotfile and `send` is initialized with `{dotfiles:
|
|
341
|
+
// 'ignore'}`. `send` aborts the request before getting far enough to
|
|
342
|
+
// check if the file exists (hence, a 404 `NotFoundError` instead of
|
|
343
|
+
// `ENOENT`).
|
|
344
|
+
// https://github.com/pillarjs/send/blob/de073ed3237ade9ff71c61673a34474b30e5d45b/index.js#L582
|
|
345
|
+
if (metadata.error.status === 404) {
|
|
346
|
+
return reply.callNotFound()
|
|
349
347
|
}
|
|
350
348
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return pumpSendToReply(
|
|
354
|
-
request,
|
|
355
|
-
reply,
|
|
356
|
-
pathnameOrig,
|
|
357
|
-
rootPath,
|
|
358
|
-
rootPathOffset,
|
|
359
|
-
undefined,
|
|
360
|
-
checkedEncodings
|
|
361
|
-
)
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return reply.callNotFound()
|
|
349
|
+
await reply.send(metadata.error)
|
|
350
|
+
break
|
|
365
351
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
352
|
+
case 'file': {
|
|
353
|
+
reply.code(statusCode)
|
|
354
|
+
if (setHeaders !== undefined) {
|
|
355
|
+
setHeaders(reply.raw, metadata.path, metadata.stat)
|
|
356
|
+
}
|
|
357
|
+
reply.headers(headers)
|
|
358
|
+
if (encoding) {
|
|
359
|
+
reply.header('content-type', getContentType(pathname))
|
|
360
|
+
reply.header('content-encoding', encoding)
|
|
361
|
+
}
|
|
362
|
+
await reply.send(stream)
|
|
363
|
+
break
|
|
375
364
|
}
|
|
376
|
-
|
|
377
|
-
reply.send(err)
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
// we cannot use pump, because send error
|
|
381
|
-
// handling is not compatible
|
|
382
|
-
stream.pipe(wrap)
|
|
365
|
+
}
|
|
383
366
|
}
|
|
384
367
|
|
|
385
368
|
function setUpHeadAndGet (routeOpts, route, file, rootPath) {
|
|
@@ -394,11 +377,11 @@ async function fastifyStatic (fastify, opts) {
|
|
|
394
377
|
fastify.route(toSetUp)
|
|
395
378
|
}
|
|
396
379
|
|
|
397
|
-
function serveFileHandler (req, reply) {
|
|
380
|
+
async function serveFileHandler (req, reply) {
|
|
398
381
|
// TODO: remove the fallback branch when bump major
|
|
399
|
-
/*
|
|
382
|
+
/* c8 ignore next */
|
|
400
383
|
const routeConfig = req.routeOptions?.config || req.routeConfig
|
|
401
|
-
pumpSendToReply(req, reply, routeConfig.file, routeConfig.rootPath)
|
|
384
|
+
return pumpSendToReply(req, reply, routeConfig.file, routeConfig.rootPath)
|
|
402
385
|
}
|
|
403
386
|
}
|
|
404
387
|
|
|
@@ -489,8 +472,6 @@ function getContentType (path) {
|
|
|
489
472
|
}
|
|
490
473
|
|
|
491
474
|
function findIndexFile (pathname, root, indexFiles = ['index.html']) {
|
|
492
|
-
// TODO remove istanbul ignore
|
|
493
|
-
/* istanbul ignore else */
|
|
494
475
|
if (Array.isArray(indexFiles)) {
|
|
495
476
|
return indexFiles.find(filename => {
|
|
496
477
|
const p = path.join(root, pathname, filename)
|
|
@@ -502,7 +483,7 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) {
|
|
|
502
483
|
}
|
|
503
484
|
})
|
|
504
485
|
}
|
|
505
|
-
/*
|
|
486
|
+
/* c8 ignore next */
|
|
506
487
|
return false
|
|
507
488
|
}
|
|
508
489
|
|
|
@@ -541,19 +522,16 @@ function getRedirectUrl (url) {
|
|
|
541
522
|
const parsed = new URL(url, 'http://localhost.com/')
|
|
542
523
|
const parsedPathname = parsed.pathname
|
|
543
524
|
return parsedPathname + (parsedPathname[parsedPathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '')
|
|
544
|
-
} catch {
|
|
525
|
+
} /* c8 ignore start */ catch {
|
|
545
526
|
// the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
|
|
546
|
-
/* istanbul ignore next */
|
|
547
527
|
const err = new Error(`Invalid redirect URL: ${url}`)
|
|
548
|
-
/* istanbul ignore next */
|
|
549
528
|
err.statusCode = 400
|
|
550
|
-
/* istanbul ignore next */
|
|
551
529
|
throw err
|
|
552
|
-
}
|
|
530
|
+
} /* c8 ignore stop */
|
|
553
531
|
}
|
|
554
532
|
|
|
555
533
|
module.exports = fp(fastifyStatic, {
|
|
556
|
-
fastify: '
|
|
534
|
+
fastify: '5.x',
|
|
557
535
|
name: '@fastify/static'
|
|
558
536
|
})
|
|
559
537
|
module.exports.default = fastifyStatic
|
package/lib/dirList.js
CHANGED
|
@@ -125,9 +125,9 @@ const dirList = {
|
|
|
125
125
|
entries.dirs.forEach(entry => nameEntries.dirs.push(entry.name))
|
|
126
126
|
entries.files.forEach(entry => nameEntries.files.push(entry.name))
|
|
127
127
|
|
|
128
|
-
reply.send(nameEntries)
|
|
128
|
+
await reply.send(nameEntries)
|
|
129
129
|
} else {
|
|
130
|
-
reply.send(entries)
|
|
130
|
+
await reply.send(entries)
|
|
131
131
|
}
|
|
132
132
|
return
|
|
133
133
|
}
|
|
@@ -135,7 +135,7 @@ const dirList = {
|
|
|
135
135
|
const html = options.render(
|
|
136
136
|
entries.dirs.map(entry => dirList.htmlInfo(entry, route, prefix, options)),
|
|
137
137
|
entries.files.map(entry => dirList.htmlInfo(entry, route, prefix, options)))
|
|
138
|
-
reply.type('text/html').send(html)
|
|
138
|
+
await reply.type('text/html').send(html)
|
|
139
139
|
},
|
|
140
140
|
|
|
141
141
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/static",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-pre.fv5.1",
|
|
4
4
|
"description": "Plugin for serving static files as fast as possible.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -31,32 +31,31 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/fastify/fastify-static",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@fastify/accept-negotiator": "^
|
|
35
|
-
"@fastify/send": "^
|
|
36
|
-
"content-disposition": "^0.5.
|
|
37
|
-
"fastify-plugin": "^
|
|
38
|
-
"fastq": "^1.17.
|
|
39
|
-
"glob": "^10.3.
|
|
34
|
+
"@fastify/accept-negotiator": "^2.0.0-pre.fv5.1",
|
|
35
|
+
"@fastify/send": "^3.1.0",
|
|
36
|
+
"content-disposition": "^0.5.4",
|
|
37
|
+
"fastify-plugin": "^5.0.0-pre.fv5.1",
|
|
38
|
+
"fastq": "^1.17.1",
|
|
39
|
+
"glob": "^10.3.10"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@fastify/compress": "^
|
|
43
|
-
"@fastify/pre-commit": "^2.0
|
|
44
|
-
"@types/node": "^20.
|
|
45
|
-
"@typescript-eslint/eslint-plugin": "^7.1
|
|
46
|
-
"@typescript-eslint/parser": "^7.1
|
|
42
|
+
"@fastify/compress": "^8.0.0-pre.fv5.1",
|
|
43
|
+
"@fastify/pre-commit": "^2.1.0",
|
|
44
|
+
"@types/node": "^20.11.30",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
46
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
47
47
|
"concat-stream": "^2.0.0",
|
|
48
|
-
"coveralls": "^3.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"simple-get": "^4.0.0",
|
|
48
|
+
"coveralls": "^3.1.1",
|
|
49
|
+
"fastify": "^5.0.0-alpha.3",
|
|
50
|
+
"handlebars": "^4.7.8",
|
|
51
|
+
"pino": "^9.1.0",
|
|
52
|
+
"proxyquire": "^2.1.3",
|
|
53
|
+
"simple-get": "^4.0.1",
|
|
55
54
|
"snazzy": "^9.0.0",
|
|
56
|
-
"standard": "^17.
|
|
57
|
-
"tap": "^
|
|
55
|
+
"standard": "^17.1.0",
|
|
56
|
+
"tap": "^18.7.1",
|
|
58
57
|
"tsd": "^0.31.0",
|
|
59
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.4.3"
|
|
60
59
|
},
|
|
61
60
|
"tsd": {
|
|
62
61
|
"directory": "test/types"
|
package/test/dir-list.test.js
CHANGED
|
@@ -171,6 +171,34 @@ t.test('dir list, custom options', t => {
|
|
|
171
171
|
})
|
|
172
172
|
})
|
|
173
173
|
|
|
174
|
+
t.test('dir list, custom options with empty array index', t => {
|
|
175
|
+
t.plan(2)
|
|
176
|
+
|
|
177
|
+
const options = {
|
|
178
|
+
root: path.join(__dirname, '/static'),
|
|
179
|
+
prefix: '/public',
|
|
180
|
+
index: [],
|
|
181
|
+
list: true
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const route = '/public/'
|
|
185
|
+
const content = { dirs: ['deep', 'shallow'], files: ['.example', '100%.txt', 'a .md', 'foo.html', 'foobar.html', 'index.css', 'index.html'] }
|
|
186
|
+
|
|
187
|
+
helper.arrange(t, options, (url) => {
|
|
188
|
+
t.test(route, t => {
|
|
189
|
+
t.plan(3)
|
|
190
|
+
simple.concat({
|
|
191
|
+
method: 'GET',
|
|
192
|
+
url: url + route
|
|
193
|
+
}, (err, response, body) => {
|
|
194
|
+
t.error(err)
|
|
195
|
+
t.equal(response.statusCode, 200)
|
|
196
|
+
t.equal(body.toString(), JSON.stringify(content))
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
174
202
|
t.test('dir list html format', t => {
|
|
175
203
|
t.plan(6)
|
|
176
204
|
|
|
@@ -471,7 +499,7 @@ t.test('dir list json format - extended info', t => {
|
|
|
471
499
|
t.equal(response.statusCode, 200)
|
|
472
500
|
const bodyObject = JSON.parse(body.toString())
|
|
473
501
|
t.equal(bodyObject.dirs[0].name, 'empty')
|
|
474
|
-
t.equal(typeof bodyObject.dirs[0].stats.
|
|
502
|
+
t.equal(typeof bodyObject.dirs[0].stats.atimeMs, 'number')
|
|
475
503
|
t.equal(typeof bodyObject.dirs[0].extendedInfo.totalSize, 'number')
|
|
476
504
|
})
|
|
477
505
|
})
|
|
@@ -845,7 +873,7 @@ t.test('dir list error', t => {
|
|
|
845
873
|
const errorMessage = 'mocking send'
|
|
846
874
|
dirList.send = async () => { throw new Error(errorMessage) }
|
|
847
875
|
|
|
848
|
-
const mock = t.
|
|
876
|
+
const mock = t.mockRequire('..', {
|
|
849
877
|
'../lib/dirList.js': dirList
|
|
850
878
|
})
|
|
851
879
|
|
package/test/static.test.js
CHANGED
|
@@ -681,7 +681,7 @@ t.test('register /static with constraints', (t) => {
|
|
|
681
681
|
})
|
|
682
682
|
})
|
|
683
683
|
|
|
684
|
-
t.test('payload.
|
|
684
|
+
t.test('payload.path is set', (t) => {
|
|
685
685
|
t.plan(3)
|
|
686
686
|
|
|
687
687
|
const pluginOptions = {
|
|
@@ -692,7 +692,7 @@ t.test('payload.filename is set', (t) => {
|
|
|
692
692
|
let gotFilename
|
|
693
693
|
fastify.register(fastifyStatic, pluginOptions)
|
|
694
694
|
fastify.addHook('onSend', function (req, reply, payload, next) {
|
|
695
|
-
gotFilename = payload.
|
|
695
|
+
gotFilename = payload.path
|
|
696
696
|
next()
|
|
697
697
|
})
|
|
698
698
|
|
|
@@ -1361,13 +1361,13 @@ t.test('root not found warning', (t) => {
|
|
|
1361
1361
|
const destination = concat((data) => {
|
|
1362
1362
|
t.equal(JSON.parse(data).msg, `"root" path "${rootPath}" must exist`)
|
|
1363
1363
|
})
|
|
1364
|
-
const
|
|
1364
|
+
const loggerInstance = pino(
|
|
1365
1365
|
{
|
|
1366
1366
|
level: 'warn'
|
|
1367
1367
|
},
|
|
1368
1368
|
destination
|
|
1369
1369
|
)
|
|
1370
|
-
const fastify = Fastify({
|
|
1370
|
+
const fastify = Fastify({ loggerInstance })
|
|
1371
1371
|
fastify.register(fastifyStatic, pluginOptions)
|
|
1372
1372
|
fastify.listen({ port: 0 }, (err) => {
|
|
1373
1373
|
t.error(err)
|