@fastify/static 8.0.3 → 8.1.0
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/.github/dependabot.yml +1 -1
- package/README.md +92 -86
- package/eslint.config.js +1 -0
- package/index.js +4 -3
- package/lib/dirList.js +1 -1
- package/package.json +36 -7
- package/test/content-type.test.js +97 -127
- package/test/dir-list.test.js +264 -369
- package/test/static.test.js +1871 -2360
- package/types/index.d.ts +2 -1
- package/types/index.test-d.ts +22 -21
- package/.eslintrc.json +0 -31
- package/.taprc +0 -2
- package/test/static/shallow/no-link +0 -1
- package/test/static-symbolic-link/dir/symlink +0 -1
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
/* eslint n/no-deprecated-api: "off" */
|
|
4
4
|
|
|
5
5
|
const path = require('node:path')
|
|
6
|
-
const { test } = require('
|
|
7
|
-
const simple = require('simple-get')
|
|
6
|
+
const { test } = require('node:test')
|
|
8
7
|
const Fastify = require('fastify')
|
|
9
8
|
|
|
10
9
|
const fastifyStatic = require('../')
|
|
11
10
|
|
|
12
|
-
test('register /content-type', t => {
|
|
13
|
-
t.plan(
|
|
11
|
+
test('register /content-type', async t => {
|
|
12
|
+
t.plan(5)
|
|
14
13
|
|
|
15
14
|
const pluginOptions = {
|
|
16
15
|
root: path.join(__dirname, '/content-type'),
|
|
@@ -19,72 +18,55 @@ test('register /content-type', t => {
|
|
|
19
18
|
const fastify = Fastify()
|
|
20
19
|
fastify.register(fastifyStatic, pluginOptions)
|
|
21
20
|
|
|
22
|
-
t.
|
|
21
|
+
t.after(() => fastify.close())
|
|
23
22
|
|
|
24
|
-
fastify.listen({ port: 0 }
|
|
25
|
-
t.error(err)
|
|
23
|
+
await fastify.listen({ port: 0 })
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
fastify.server.unref()
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
})
|
|
27
|
+
await t.test('/content-type/index.html', async (t) => {
|
|
28
|
+
t.plan(2)
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
})
|
|
30
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html')
|
|
31
|
+
t.assert.ok(response.ok)
|
|
32
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
|
|
33
|
+
})
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
})
|
|
35
|
+
await t.test('/content-type/index.css', async (t) => {
|
|
36
|
+
t.plan(2)
|
|
61
37
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
})
|
|
38
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css')
|
|
39
|
+
t.assert.ok(response.ok)
|
|
40
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
|
|
41
|
+
})
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
43
|
+
await t.test('/content-type/sample.jpg', async (t) => {
|
|
44
|
+
t.plan(2)
|
|
45
|
+
|
|
46
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg')
|
|
47
|
+
t.assert.ok(response.ok)
|
|
48
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
await t.test('/content-type/test.txt', async (t) => {
|
|
52
|
+
t.plan(2)
|
|
53
|
+
|
|
54
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt')
|
|
55
|
+
t.assert.ok(response.ok)
|
|
56
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
await t.test('/content-type/binary', async (t) => {
|
|
60
|
+
t.plan(2)
|
|
61
|
+
|
|
62
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary')
|
|
63
|
+
t.assert.ok(response.ok)
|
|
64
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
|
|
83
65
|
})
|
|
84
66
|
})
|
|
85
67
|
|
|
86
|
-
test('register /content-type preCompressed', t => {
|
|
87
|
-
t.plan(
|
|
68
|
+
test('register /content-type preCompressed', async t => {
|
|
69
|
+
t.plan(5)
|
|
88
70
|
|
|
89
71
|
const pluginOptions = {
|
|
90
72
|
root: path.join(__dirname, '/content-type'),
|
|
@@ -94,81 +76,69 @@ test('register /content-type preCompressed', t => {
|
|
|
94
76
|
const fastify = Fastify()
|
|
95
77
|
fastify.register(fastifyStatic, pluginOptions)
|
|
96
78
|
|
|
97
|
-
t.
|
|
98
|
-
|
|
99
|
-
fastify.listen({ port: 0 }
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
t.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
})
|
|
79
|
+
t.after(() => fastify.close())
|
|
80
|
+
|
|
81
|
+
await fastify.listen({ port: 0 })
|
|
82
|
+
|
|
83
|
+
fastify.server.unref()
|
|
84
|
+
|
|
85
|
+
await t.test('/content-type/index.html', async (t) => {
|
|
86
|
+
t.plan(2)
|
|
87
|
+
|
|
88
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.html', {
|
|
89
|
+
headers: {
|
|
90
|
+
'accept-encoding': 'gzip, deflate, br'
|
|
91
|
+
}
|
|
116
92
|
})
|
|
93
|
+
t.assert.ok(response.ok)
|
|
94
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/html; charset=utf-8')
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
await t.test('/content-type/index.css', async (t) => {
|
|
98
|
+
t.plan(2)
|
|
117
99
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
})
|
|
100
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/index.css', {
|
|
101
|
+
headers: {
|
|
102
|
+
'accept-encoding': 'gzip, deflate, br'
|
|
103
|
+
}
|
|
130
104
|
})
|
|
105
|
+
t.assert.ok(response.ok)
|
|
106
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/css; charset=utf-8')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
await t.test('/content-type/sample.jpg', async (t) => {
|
|
110
|
+
t.plan(2)
|
|
131
111
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
})
|
|
112
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/sample.jpg', {
|
|
113
|
+
headers: {
|
|
114
|
+
'accept-encoding': 'gzip, deflate, br'
|
|
115
|
+
}
|
|
144
116
|
})
|
|
117
|
+
t.assert.ok(response.ok)
|
|
118
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'image/jpeg')
|
|
119
|
+
})
|
|
145
120
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
}, (err, response) => {
|
|
155
|
-
t.error(err)
|
|
156
|
-
t.equal(response.headers['content-type'], 'text/plain; charset=utf-8')
|
|
157
|
-
})
|
|
121
|
+
await t.test('/content-type/test.txt', async (t) => {
|
|
122
|
+
t.plan(2)
|
|
123
|
+
|
|
124
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/test.txt', {
|
|
125
|
+
headers: {
|
|
126
|
+
'accept-encoding': 'gzip, deflate, br'
|
|
127
|
+
}
|
|
158
128
|
})
|
|
129
|
+
t.assert.ok(response.ok)
|
|
130
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'text/plain; charset=utf-8')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
await t.test('/content-type/binary', async (t) => {
|
|
134
|
+
t.plan(2)
|
|
159
135
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
})
|
|
136
|
+
const response = await fetch('http://localhost:' + fastify.server.address().port + '/content-type/binary', {
|
|
137
|
+
headers: {
|
|
138
|
+
'accept-encoding': 'gzip, deflate, br'
|
|
139
|
+
}
|
|
172
140
|
})
|
|
141
|
+
t.assert.ok(response.ok)
|
|
142
|
+
t.assert.deepStrictEqual(response.headers.get('content-type'), 'application/octet-stream')
|
|
173
143
|
})
|
|
174
144
|
})
|