@fastify/static
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -164,3 +164,4 @@ 'use strict' | ||
route: pathname, | ||
prefix | ||
prefix, | ||
dotfiles: opts.dotfiles | ||
}).catch((err) => reply.send(err)) | ||
@@ -221,3 +222,4 @@ return | ||
route: pathname, | ||
prefix | ||
prefix, | ||
dotfiles: opts.dotfiles | ||
}).catch((err) => reply.send(err)) | ||
@@ -224,0 +226,0 @@ return |
@@ -11,8 +11,12 @@ 'use strict' | ||
* @param {string} dir full path fs dir | ||
* @param {function(error, entries)} callback | ||
* @param {ListOptions} options | ||
* @param {string} dotfiles | ||
* note: can't use glob because don't get error on non existing dir | ||
*/ | ||
list: async function (dir, options) { | ||
list: async function (dir, options, dotfiles) { | ||
const entries = { dirs: [], files: [] } | ||
const files = await fs.readdir(dir) | ||
let files = await fs.readdir(dir) | ||
if (dotfiles === 'deny' || dotfiles === 'ignore') { | ||
files = files.filter(f => f.charAt(0) !== '.') | ||
} | ||
if (files.length < 1) { | ||
@@ -101,7 +105,8 @@ return entries | ||
* @param {string} route request route | ||
* @param {string} dotfiles | ||
*/ | ||
send: async function ({ reply, dir, options, route, prefix }) { | ||
send: async function ({ reply, dir, options, route, prefix, dotfiles }) { | ||
let entries | ||
try { | ||
entries = await dirList.list(dir, options) | ||
entries = await dirList.list(dir, options, dotfiles) | ||
} catch (error) { | ||
@@ -108,0 +113,0 @@ return reply.callNotFound() |
{ | ||
"name": "@fastify/static", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "Plugin for serving static files as fast as possible.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -193,3 +193,5 @@ # @fastify/static | ||
Note: Multi-root is not supported within the `list` option. | ||
Note: | ||
- Multi-root is not supported within the `list` option. | ||
- If `dotfiles` option value is `deny` or `ignore`, dotfiles will be excluded. | ||
@@ -196,0 +198,0 @@ **Example:** |
@@ -639,2 +639,86 @@ 'use strict' | ||
t.test('dir list with dotfiles allow option', t => { | ||
t.plan(2) | ||
const options = { | ||
root: path.join(__dirname, '/static-dotfiles'), | ||
prefix: '/public', | ||
dotfiles: 'allow', | ||
index: false, | ||
list: true | ||
} | ||
const route = '/public/' | ||
const content = { dirs: ['dir'], files: ['.aaa', 'test.txt'] } | ||
helper.arrange(t, options, (url) => { | ||
t.test(route, t => { | ||
t.plan(3) | ||
simple.concat({ | ||
method: 'GET', | ||
url: url + route | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.equal(response.statusCode, 200) | ||
t.equal(body.toString(), JSON.stringify(content)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
t.test('dir list with dotfiles deny option', t => { | ||
t.plan(2) | ||
const options = { | ||
root: path.join(__dirname, '/static-dotfiles'), | ||
prefix: '/public', | ||
dotfiles: 'deny', | ||
index: false, | ||
list: true | ||
} | ||
const route = '/public/' | ||
const content = { dirs: ['dir'], files: ['test.txt'] } | ||
helper.arrange(t, options, (url) => { | ||
t.test(route, t => { | ||
t.plan(3) | ||
simple.concat({ | ||
method: 'GET', | ||
url: url + route | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.equal(response.statusCode, 200) | ||
t.equal(body.toString(), JSON.stringify(content)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
t.test('dir list with dotfiles ignore option', t => { | ||
t.plan(2) | ||
const options = { | ||
root: path.join(__dirname, '/static-dotfiles'), | ||
prefix: '/public', | ||
dotfiles: 'ignore', | ||
index: false, | ||
list: true | ||
} | ||
const route = '/public/' | ||
const content = { dirs: ['dir'], files: ['test.txt'] } | ||
helper.arrange(t, options, (url) => { | ||
t.test(route, t => { | ||
t.plan(3) | ||
simple.concat({ | ||
method: 'GET', | ||
url: url + route | ||
}, (err, response, body) => { | ||
t.error(err) | ||
t.equal(response.statusCode, 200) | ||
t.equal(body.toString(), JSON.stringify(content)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
t.test('dir list error', t => { | ||
@@ -641,0 +725,0 @@ t.plan(7) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
357770
50
4591
442