-
-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Labels
good first issueGood for newcomersGood for newcomerssemver-minorIssue or PR that should land as semver minorIssue or PR that should land as semver minor
Description
🚀 Feature Proposal
Support filtering files by extension.
Motivation
Sometimes you may want to keep your JavaScript or CSS files alongside a component. For those not using build steps, it'd be great to have the ability to filter what files to serve by pointing root at the directory, but only serving certain files based off extension (or more generically could be pattern matching in general).
Example
Assume we have the following directory structure:
src/
├── components/
│ ├── cool-feature
│ │ ├── index.pug
│ │ ├── index.js
│ │ └── index.css
We'd register our plugin like so (assume PWD is src):
app.register(require('fastify-static'), {
root: path.join(__dirname, 'components')],
prefix: '/static',
extensions: ['.js', '.css'],
});Example of general pattern instead:
app.register(require('fastify-static'), {
root: path.join(__dirname, 'components')],
prefix: '/static',
filter: /\.(?:js|css)$/,
});Examples of access:
/static/cool-feature/index.js -> SUCCESS
/static/cool-feature/index.css -> SUCCESS
/static/cool-feature/index.pug -> 404
zekth
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomerssemver-minorIssue or PR that should land as semver minorIssue or PR that should land as semver minor