fastify 4.0.0 → 4.0.3
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/.markdownlint-cli2.yaml +22 -0
- package/GOVERNANCE.md +30 -20
- package/PROJECT_CHARTER.md +48 -17
- package/README.md +165 -78
- package/SECURITY.md +55 -44
- package/build/build-error-serializer.js +12 -7
- package/docs/Guides/Benchmarking.md +2 -0
- package/docs/Guides/Delay-Accepting-Requests.md +98 -90
- package/docs/Guides/Ecosystem.md +43 -30
- package/docs/Guides/Index.md +2 -0
- package/docs/Guides/Migration-Guide-V4.md +55 -0
- package/docs/Guides/Serverless.md +13 -12
- package/docs/Reference/ContentTypeParser.md +17 -13
- package/docs/Reference/Errors.md +6 -5
- package/docs/Reference/LTS.md +2 -2
- package/docs/Reference/Plugins.md +8 -6
- package/docs/Reference/Reply.md +30 -16
- package/docs/Reference/Request.md +3 -3
- package/docs/Reference/Routes.md +112 -37
- package/docs/Reference/Server.md +109 -72
- package/docs/Reference/Type-Providers.md +30 -9
- package/docs/Reference/TypeScript.md +12 -6
- package/docs/Reference/Validation-and-Serialization.md +39 -37
- package/fastify.js +1 -1
- package/lib/error-serializer.js +171 -175
- package/lib/pluginUtils.js +10 -0
- package/lib/reply.js +1 -1
- package/lib/server.js +9 -1
- package/lib/wrapThenable.js +8 -3
- package/package.json +8 -6
- package/test/build/error-serializer.test.js +28 -0
- package/test/{internals → build}/version.test.js +1 -1
- package/test/listen.test.js +16 -2
- package/test/plugin.test.js +32 -0
- package/test/reply-error.test.js +7 -1
- package/test/stream.test.js +73 -0
- package/docs/Migration-Guide-V4.md +0 -12
package/test/stream.test.js
CHANGED
|
@@ -741,3 +741,76 @@ test('reply.send handles aborted requests', t => {
|
|
|
741
741
|
}, 1)
|
|
742
742
|
})
|
|
743
743
|
})
|
|
744
|
+
|
|
745
|
+
test('request terminated should not crash fastify', t => {
|
|
746
|
+
t.plan(10)
|
|
747
|
+
|
|
748
|
+
const spyLogger = {
|
|
749
|
+
level: 'error',
|
|
750
|
+
fatal: () => { },
|
|
751
|
+
error: () => {
|
|
752
|
+
t.fail('should not log an error')
|
|
753
|
+
},
|
|
754
|
+
warn: () => { },
|
|
755
|
+
info: () => { },
|
|
756
|
+
debug: () => { },
|
|
757
|
+
trace: () => { },
|
|
758
|
+
child: () => { return spyLogger }
|
|
759
|
+
}
|
|
760
|
+
const fastify = Fastify({
|
|
761
|
+
logger: spyLogger
|
|
762
|
+
})
|
|
763
|
+
|
|
764
|
+
fastify.get('/', async (req, reply) => {
|
|
765
|
+
const stream = new Readable()
|
|
766
|
+
stream._read = () => {}
|
|
767
|
+
reply.header('content-type', 'text/html; charset=utf-8')
|
|
768
|
+
reply.header('transfer-encoding', 'chunked')
|
|
769
|
+
stream.push('<h1>HTML</h1>')
|
|
770
|
+
|
|
771
|
+
reply.send(stream)
|
|
772
|
+
|
|
773
|
+
await new Promise((resolve) => { setTimeout(resolve, 6).unref() })
|
|
774
|
+
|
|
775
|
+
stream.push('<h1>should disply on second stream</h1>')
|
|
776
|
+
stream.push(null)
|
|
777
|
+
return reply
|
|
778
|
+
})
|
|
779
|
+
|
|
780
|
+
fastify.listen({ port: 0 }, err => {
|
|
781
|
+
t.error(err)
|
|
782
|
+
t.teardown(() => { fastify.close() })
|
|
783
|
+
|
|
784
|
+
const port = fastify.server.address().port
|
|
785
|
+
const http = require('http')
|
|
786
|
+
const req = http.get(`http://localhost:${port}`, function (res) {
|
|
787
|
+
const { statusCode, headers } = res
|
|
788
|
+
t.equal(statusCode, 200)
|
|
789
|
+
t.equal(headers['content-type'], 'text/html; charset=utf-8')
|
|
790
|
+
t.equal(headers['transfer-encoding'], 'chunked')
|
|
791
|
+
res.on('data', function (chunk) {
|
|
792
|
+
t.equal(chunk.toString(), '<h1>HTML</h1>')
|
|
793
|
+
})
|
|
794
|
+
|
|
795
|
+
setTimeout(() => {
|
|
796
|
+
req.destroy()
|
|
797
|
+
|
|
798
|
+
// the server is not crash, we can connect it
|
|
799
|
+
http.get(`http://localhost:${port}`, function (res) {
|
|
800
|
+
const { statusCode, headers } = res
|
|
801
|
+
t.equal(statusCode, 200)
|
|
802
|
+
t.equal(headers['content-type'], 'text/html; charset=utf-8')
|
|
803
|
+
t.equal(headers['transfer-encoding'], 'chunked')
|
|
804
|
+
let payload = ''
|
|
805
|
+
res.on('data', function (chunk) {
|
|
806
|
+
payload += chunk.toString()
|
|
807
|
+
})
|
|
808
|
+
res.on('end', function () {
|
|
809
|
+
t.equal(payload, '<h1>HTML</h1><h1>should disply on second stream</h1>')
|
|
810
|
+
t.pass('should end properly')
|
|
811
|
+
})
|
|
812
|
+
})
|
|
813
|
+
}, 1)
|
|
814
|
+
})
|
|
815
|
+
})
|
|
816
|
+
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# V4 Migration Guide
|
|
2
|
-
|
|
3
|
-
This guide is intended to help with migration from Fastify v3 to v4.
|
|
4
|
-
|
|
5
|
-
Before migrating to v4, please ensure that you have fixed all deprecation warningx from v3.
|
|
6
|
-
All v3 deprecations have been removed and they will no longer work after upgrading.
|
|
7
|
-
|
|
8
|
-
## Breaking Changes
|
|
9
|
-
|
|
10
|
-
### Deprecation of `app.use()`
|
|
11
|
-
|
|
12
|
-
Starting this version of Fastify, we have deprecated the use of `app.use()`. We have decided not to support the use of middlewares. Both [`@fastify/middie`](https://github.com/fastify/middie) and [`@fastify/express`](https://github.com/fastify/fastify-express) will still be there and maintained. Use Fastify's [hooks](./Reference/Hooks.md) instead.
|