Skip to content

Commit

Permalink
fix: add contentType send option
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Nov 22, 2024
1 parent 9af3316 commit 2f3bf8b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ The following options are also supported and will be passed directly to the
[`@fastify/send`](https://www.npmjs.com/package/@fastify/send) module:

- [`acceptRanges`](https://www.npmjs.com/package/@fastify/send#acceptranges)
- [`contentType`](https://www.npmjs.com/package/@fastify/send#contenttype)
- [`cacheControl`](https://www.npmjs.com/package/@fastify/send#cachecontrol) (Enable or disable setting Cache-Control response header, defaults to true. **Important:** If you want to provide a custom Cache-Control response header, this option must be false.)
- [`dotfiles`](https://www.npmjs.com/package/@fastify/send#dotfiles)
- [`etag`](https://www.npmjs.com/package/@fastify/send#etag)
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function fastifyStatic (fastify, opts) {
const sendOptions = {
root: opts.root,
acceptRanges: opts.acceptRanges,
contentType: opts.contentType,
cacheControl: opts.cacheControl,
dotfiles: opts.dotfiles,
etag: opts.etag,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"homepage": "https://github.com/fastify/fastify-static",
"dependencies": {
"@fastify/accept-negotiator": "^2.0.0",
"@fastify/send": "^3.1.0",
"@fastify/send": "^3.2.0",
"content-disposition": "^0.5.4",
"fastify-plugin": "^5.0.0",
"fastq": "^1.17.1",
Expand Down
4 changes: 3 additions & 1 deletion test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,11 @@ t.test('root not found warning', (t) => {
})

t.test('send options', (t) => {
t.plan(11)
t.plan(12)
const pluginOptions = {
root: path.join(__dirname, '/static'),
acceptRanges: 'acceptRanges',
contentType: 'contentType',
cacheControl: 'cacheControl',
dotfiles: 'dotfiles',
etag: 'etag',
Expand All @@ -1396,6 +1397,7 @@ t.test('send options', (t) => {
t.equal(pathName, '/index.html')
t.equal(options.root, path.join(__dirname, '/static'))
t.equal(options.acceptRanges, 'acceptRanges')
t.equal(options.contentType, 'contentType')
t.equal(options.cacheControl, 'cacheControl')
t.equal(options.dotfiles, 'dotfiles')
t.equal(options.etag, 'etag')
Expand Down
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ declare namespace fastifyStatic {
// Passed on to `send`
export interface SendOptions {
acceptRanges?: boolean;
contentType?: boolean;
cacheControl?: boolean;
dotfiles?: 'allow' | 'deny' | 'ignore';
etag?: boolean;
Expand Down Expand Up @@ -103,6 +104,7 @@ declare namespace fastifyStatic {

// Passed on to `send`
acceptRanges?: boolean;
contentType?: boolean;
cacheControl?: boolean;
dotfiles?: 'allow' | 'deny' | 'ignore';
etag?: boolean;
Expand Down
1 change: 1 addition & 0 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ expectType<any>(fastifyStaticCjs)
const appWithImplicitHttp = fastify()
const options: FastifyStaticOptions = {
acceptRanges: true,
contentType: true,
cacheControl: true,
decorateReply: true,
dotfiles: 'allow',
Expand Down

0 comments on commit 2f3bf8b

Please sign in to comment.