@fastify/static 6.10.1 → 6.10.2

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.
@@ -2,6 +2,11 @@ name: CI
2
2
 
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - main
7
+ - master
8
+ - next
9
+ - 'v*'
5
10
  paths-ignore:
6
11
  - 'docs/**'
7
12
  - '*.md'
package/index.js CHANGED
@@ -12,6 +12,8 @@ const util = require('util')
12
12
  const globPromise = util.promisify(glob)
13
13
  const encodingNegotiator = require('@fastify/accept-negotiator')
14
14
 
15
+ send.mime.default_type = 'application/octet-stream'
16
+
15
17
  const dirList = require('./lib/dirList')
16
18
 
17
19
  async function fastifyStatic (fastify, opts) {
@@ -476,7 +478,7 @@ function checkPath (fastify, rootPath) {
476
478
  const supportedEncodings = ['br', 'gzip', 'deflate']
477
479
 
478
480
  function getContentType (path) {
479
- const type = send.mime.getType(path)
481
+ const type = send.mime.getType(path) || send.mime.default_type
480
482
 
481
483
  if (!send.isUtf8MimeType(type)) {
482
484
  return type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/static",
3
- "version": "6.10.1",
3
+ "version": "6.10.2",
4
4
  "description": "Plugin for serving static files as fast as possible.",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@fastify/compress": "^6.0.0",
42
42
  "@fastify/pre-commit": "^2.0.2",
43
- "@types/node": "^18.0.0",
43
+ "@types/node": "^20.1.0",
44
44
  "@typescript-eslint/eslint-plugin": "^2.29.0",
45
45
  "@typescript-eslint/parser": "^2.29.0",
46
46
  "concat-stream": "^2.0.0",
File without changes
@@ -0,0 +1 @@
1
+ �
File without changes
@@ -0,0 +1 @@
1
+ �
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ the body
4
+ </body>
5
+ </html>
Binary file
Binary file
Binary file
File without changes
@@ -0,0 +1 @@
1
+ �
@@ -0,0 +1,174 @@
1
+ 'use strict'
2
+
3
+ /* eslint n/no-deprecated-api: "off" */
4
+
5
+ const path = require('path')
6
+ const { test } = require('tap')
7
+ const simple = require('simple-get')
8
+ const Fastify = require('fastify')
9
+
10
+ const fastifyStatic = require('../')
11
+
12
+ test('register /content-type', t => {
13
+ t.plan(6)
14
+
15
+ const pluginOptions = {
16
+ root: path.join(__dirname, '/content-type'),
17
+ prefix: '/content-type'
18
+ }
19
+ const fastify = Fastify()
20
+ fastify.register(fastifyStatic, pluginOptions)
21
+
22
+ t.teardown(fastify.close.bind(fastify))
23
+
24
+ fastify.listen({ port: 0 }, (err) => {
25
+ t.error(err)
26
+
27
+ fastify.server.unref()
28
+
29
+ t.test('/content-type/index.html', (t) => {
30
+ t.plan(2)
31
+ simple.concat({
32
+ method: 'GET',
33
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html'
34
+ }, (err, response) => {
35
+ t.error(err)
36
+ t.equal(response.headers['content-type'], 'text/html; charset=UTF-8')
37
+ })
38
+ })
39
+
40
+ t.test('/content-type/index.css', (t) => {
41
+ t.plan(2)
42
+ simple.concat({
43
+ method: 'GET',
44
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css'
45
+ }, (err, response) => {
46
+ t.error(err)
47
+ t.equal(response.headers['content-type'], 'text/css; charset=UTF-8')
48
+ })
49
+ })
50
+
51
+ t.test('/content-type/sample.jpg', (t) => {
52
+ t.plan(2)
53
+ simple.concat({
54
+ method: 'GET',
55
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg'
56
+ }, (err, response) => {
57
+ t.error(err)
58
+ t.equal(response.headers['content-type'], 'image/jpeg')
59
+ })
60
+ })
61
+
62
+ t.test('/content-type/test.txt', (t) => {
63
+ t.plan(2)
64
+ simple.concat({
65
+ method: 'GET',
66
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt'
67
+ }, (err, response) => {
68
+ t.error(err)
69
+ t.equal(response.headers['content-type'], 'text/plain; charset=UTF-8')
70
+ })
71
+ })
72
+
73
+ t.test('/content-type/binary', (t) => {
74
+ t.plan(2)
75
+ simple.concat({
76
+ method: 'GET',
77
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary'
78
+ }, (err, response) => {
79
+ t.error(err)
80
+ t.equal(response.headers['content-type'], 'application/octet-stream')
81
+ })
82
+ })
83
+ })
84
+ })
85
+
86
+ test('register /content-type preCompressed', t => {
87
+ t.plan(6)
88
+
89
+ const pluginOptions = {
90
+ root: path.join(__dirname, '/content-type'),
91
+ prefix: '/content-type',
92
+ preCompressed: true
93
+ }
94
+ const fastify = Fastify()
95
+ fastify.register(fastifyStatic, pluginOptions)
96
+
97
+ t.teardown(fastify.close.bind(fastify))
98
+
99
+ fastify.listen({ port: 0 }, (err) => {
100
+ t.error(err)
101
+
102
+ fastify.server.unref()
103
+
104
+ t.test('/content-type/index.html', (t) => {
105
+ t.plan(2)
106
+ simple.concat({
107
+ method: 'GET',
108
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.html',
109
+ headers: {
110
+ 'accept-encoding': 'gzip, deflate, br'
111
+ }
112
+ }, (err, response) => {
113
+ t.error(err)
114
+ t.equal(response.headers['content-type'], 'text/html; charset=UTF-8')
115
+ })
116
+ })
117
+
118
+ t.test('/content-type/index.css', (t) => {
119
+ t.plan(2)
120
+ simple.concat({
121
+ method: 'GET',
122
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/index.css',
123
+ headers: {
124
+ 'accept-encoding': 'gzip, deflate, br'
125
+ }
126
+ }, (err, response) => {
127
+ t.error(err)
128
+ t.equal(response.headers['content-type'], 'text/css; charset=UTF-8')
129
+ })
130
+ })
131
+
132
+ t.test('/content-type/sample.jpg', (t) => {
133
+ t.plan(2)
134
+ simple.concat({
135
+ method: 'GET',
136
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg',
137
+ headers: {
138
+ 'accept-encoding': 'gzip, deflate, br'
139
+ }
140
+ }, (err, response) => {
141
+ t.error(err)
142
+ t.equal(response.headers['content-type'], 'image/jpeg')
143
+ })
144
+ })
145
+
146
+ t.test('/content-type/test.txt', (t) => {
147
+ t.plan(2)
148
+ simple.concat({
149
+ method: 'GET',
150
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/test.txt',
151
+ headers: {
152
+ 'accept-encoding': 'gzip, deflate, br'
153
+ }
154
+ }, (err, response) => {
155
+ t.error(err)
156
+ t.equal(response.headers['content-type'], 'text/plain; charset=UTF-8')
157
+ })
158
+ })
159
+
160
+ t.test('/content-type/binary', (t) => {
161
+ t.plan(2)
162
+ simple.concat({
163
+ method: 'GET',
164
+ url: 'http://localhost:' + fastify.server.address().port + '/content-type/binary',
165
+ headers: {
166
+ 'accept-encoding': 'gzip, deflate, br'
167
+ }
168
+ }, (err, response) => {
169
+ t.error(err)
170
+ t.equal(response.headers['content-type'], 'application/octet-stream')
171
+ })
172
+ })
173
+ })
174
+ })