@fastify/static 8.0.2 → 8.0.4

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/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 {
@@ -72,6 +72,7 @@ declare namespace fastifyStatic {
72
72
  // Passed on to `send`
73
73
  export interface SendOptions {
74
74
  acceptRanges?: boolean;
75
+ contentType?: boolean;
75
76
  cacheControl?: boolean;
76
77
  dotfiles?: 'allow' | 'deny' | 'ignore';
77
78
  etag?: boolean;
@@ -103,6 +104,7 @@ declare namespace fastifyStatic {
103
104
 
104
105
  // Passed on to `send`
105
106
  acceptRanges?: boolean;
107
+ contentType?: boolean;
106
108
  cacheControl?: boolean;
107
109
  dotfiles?: 'allow' | 'deny' | 'ignore';
108
110
  etag?: boolean;
@@ -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, {
@@ -13,13 +13,13 @@ const fastifyStaticCjs = require('..')
13
13
 
14
14
  const app: FastifyInstance = fastify()
15
15
 
16
- app.register(fastifyStatic)
17
- app.register(fastifyStaticNamed)
18
- app.register(fastifyStaticCjs)
19
- app.register(fastifyStaticCjsImport.default)
20
- app.register(fastifyStaticCjsImport.fastifyStatic)
21
- app.register(fastifyStaticStar.default)
22
- app.register(fastifyStaticStar.fastifyStatic)
16
+ app.register(fastifyStatic, { root: __dirname })
17
+ app.register(fastifyStaticNamed, { root: __dirname })
18
+ app.register(fastifyStaticCjs, { root: __dirname })
19
+ app.register(fastifyStaticCjsImport.default, { root: __dirname })
20
+ app.register(fastifyStaticCjsImport.fastifyStatic, { root: __dirname })
21
+ app.register(fastifyStaticStar.default, { root: __dirname })
22
+ app.register(fastifyStaticStar.fastifyStatic, { root: __dirname })
23
23
 
24
24
  expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStatic)
25
25
  expectType<FastifyPluginAsync<FastifyStaticOptions, Server>>(fastifyStaticNamed)
@@ -34,6 +34,7 @@ expectType<any>(fastifyStaticCjs)
34
34
  const appWithImplicitHttp = fastify()
35
35
  const options: FastifyStaticOptions = {
36
36
  acceptRanges: true,
37
+ contentType: true,
37
38
  cacheControl: true,
38
39
  decorateReply: true,
39
40
  dotfiles: 'allow',
@@ -61,7 +62,7 @@ const options: FastifyStaticOptions = {
61
62
  expectType<Stats>(stat)
62
63
  },
63
64
  preCompressed: false,
64
- allowedPath: (pathName: string, root: string, request: FastifyRequest) => {
65
+ allowedPath: (_pathName: string, _root: string, _request: FastifyRequest) => {
65
66
  return true
66
67
  },
67
68
  constraints: {
@@ -120,7 +121,7 @@ expectAssignable<FastifyStaticOptions>({
120
121
  appWithImplicitHttp
121
122
  .register(fastifyStatic, options)
122
123
  .after(() => {
123
- appWithImplicitHttp.get('/', (request, reply) => {
124
+ appWithImplicitHttp.get('/', (_request, reply) => {
124
125
  reply.sendFile('some-file-name')
125
126
  })
126
127
  })
@@ -130,21 +131,25 @@ const appWithHttp2 = fastify({ http2: true })
130
131
  appWithHttp2
131
132
  .register(fastifyStatic, options)
132
133
  .after(() => {
133
- appWithHttp2.get('/', (request, reply) => {
134
+ appWithHttp2.get('/', (_request, reply) => {
134
135
  reply.sendFile('some-file-name')
135
136
  })
136
137
 
137
- appWithHttp2.get('/download', (request, reply) => {
138
+ appWithHttp2.get('/download', (_request, reply) => {
138
139
  reply.download('some-file-name')
139
140
  })
140
141
 
141
- appWithHttp2.get('/download/1', (request, reply) => {
142
+ appWithHttp2.get('/download/1', (_request, reply) => {
142
143
  reply.download('some-file-name', { maxAge: '2 days' })
143
144
  })
144
145
 
145
- appWithHttp2.get('/download/2', (request, reply) => {
146
+ appWithHttp2.get('/download/2', (_request, reply) => {
146
147
  reply.download('some-file-name', 'some-filename', { cacheControl: false, acceptRanges: true })
147
148
  })
149
+
150
+ appWithHttp2.get('/download/3', (_request, reply) => {
151
+ reply.download('some-file-name', 'some-filename', { contentType: false })
152
+ })
148
153
  })
149
154
 
150
155
  const multiRootAppWithImplicitHttp = fastify()
@@ -153,29 +158,37 @@ options.root = ['']
153
158
  multiRootAppWithImplicitHttp
154
159
  .register(fastifyStatic, options)
155
160
  .after(() => {
156
- multiRootAppWithImplicitHttp.get('/', (request, reply) => {
161
+ multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
157
162
  reply.sendFile('some-file-name')
158
163
  })
159
164
 
160
- multiRootAppWithImplicitHttp.get('/', (request, reply) => {
165
+ multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
161
166
  reply.sendFile('some-file-name', { cacheControl: false, acceptRanges: true })
162
167
  })
163
168
 
164
- multiRootAppWithImplicitHttp.get('/', (request, reply) => {
169
+ multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
165
170
  reply.sendFile('some-file-name', 'some-root-name', { cacheControl: false, acceptRanges: true })
166
171
  })
167
172
 
168
- multiRootAppWithImplicitHttp.get('/download', (request, reply) => {
173
+ multiRootAppWithImplicitHttp.get('/', (_request, reply) => {
174
+ reply.sendFile('some-file-name', 'some-root-name-2', { contentType: false })
175
+ })
176
+
177
+ multiRootAppWithImplicitHttp.get('/download', (_request, reply) => {
169
178
  reply.download('some-file-name')
170
179
  })
171
180
 
172
- multiRootAppWithImplicitHttp.get('/download/1', (request, reply) => {
181
+ multiRootAppWithImplicitHttp.get('/download/1', (_request, reply) => {
173
182
  reply.download('some-file-name', { maxAge: '2 days' })
174
183
  })
175
184
 
176
- multiRootAppWithImplicitHttp.get('/download/2', (request, reply) => {
185
+ multiRootAppWithImplicitHttp.get('/download/2', (_request, reply) => {
177
186
  reply.download('some-file-name', 'some-filename', { cacheControl: false, acceptRanges: true })
178
187
  })
188
+
189
+ multiRootAppWithImplicitHttp.get('/download/3', (_request, reply) => {
190
+ reply.download('some-file-name', 'some-filename', { contentType: false })
191
+ })
179
192
  })
180
193
 
181
194
  const noIndexApp = fastify()
@@ -185,7 +198,7 @@ options.index = false
185
198
  noIndexApp
186
199
  .register(fastifyStatic, options)
187
200
  .after(() => {
188
- noIndexApp.get('/', (request, reply) => {
201
+ noIndexApp.get('/', (_request, reply) => {
189
202
  reply.send('<h1>fastify-static</h1>')
190
203
  })
191
204
  })
@@ -195,7 +208,7 @@ options.root = new URL('')
195
208
  const URLRootApp = fastify()
196
209
  URLRootApp.register(fastifyStatic, options)
197
210
  .after(() => {
198
- URLRootApp.get('/', (request, reply) => {
211
+ URLRootApp.get('/', (_request, reply) => {
199
212
  reply.send('<h1>fastify-static</h1>')
200
213
  })
201
214
  })
@@ -206,7 +219,7 @@ options.index = 'index.html'
206
219
  defaultIndexApp
207
220
  .register(fastifyStatic, options)
208
221
  .after(() => {
209
- defaultIndexApp.get('/', (request, reply) => {
222
+ defaultIndexApp.get('/', (_request, reply) => {
210
223
  reply.send('<h1>fastify-static</h1>')
211
224
  })
212
225
  })
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,2 +0,0 @@
1
- files:
2
- - test/**/*.test.js