-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(platform-fastify): supports fastify 3.0 #5070
Conversation
Pull Request Test Coverage Report for Build 23f04693-e216-4d8c-ac60-47e1e3cf9ce3
💛 - Coveralls |
We might need to introduce a lot more breaking changes than anticipated. This is mainly because in Fastify 3.0 official support for Express-style middlewares are dropped and we need to use the plugin This will likely result in breaking changes in |
We should be able to just register the |
Sure, I'll try this and send a new PR this weekend. |
In this case we might need to introduce a breaking change in |
Why https://github.com/fastify/middie instead https://github.com/fastify/fastify-express ? |
both work :) I'm using |
@hongyiweiwu since fastify-express seems to be the recommended way for fastify 3 according the release notes https://github.com/fastify/fastify/releases/tag/v3.0.0, I recommend use that package :D |
@gperdomor I think The point from using Fastify adaper is to deliver better performance, it's bad idea to run all middleware in express instance. Maybe this will be braking change if the previous version of fastify used express instance to run middleware is this case and to avoid that using |
I agree with @AliYusuf95 as IMO fastify ecosystem is matured enough to replace express plugins. Most of the plugins are already available in fastify ecosystem i.e cors, helmet, IDK about passport though, with better performace. Nest v8 might be the version with already great DX of nestjs and with insane performace of fastify v3. |
Using middie shouldn't introduce any breaking changes. Fastify was never fully compatible with Express. |
I suppose then |
Still not sure how using middie will avoid breaking changes -- we have to async load the plugin, which will break things. |
@kamilmysliwiec This implementation isn't workable yet, because I'm hoping to hear more of your input on how to handle the breaking change in the testing module. So we shouldn't merge it yet. Currently it may break many code. |
I've changed several things in this commit (which should make it workable). Please, check them out here 0006d31 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Current
platform-fastify
package only supports Fastify 2.0.What is the new behavior?
The package is fully Fastify 3.0 compatible. In addition, the following non-breaking changes are made:
TServer
,TRawRequest
,TRawResponse
that make the type suggestions clearer.useStaticAssets
originally took a subset of options available to the Fastify instance function with the same name. It now takes the same options interface.Does this PR introduce a breaking change?
The following breaking changes are not really breaking if you were using the package correctly before.
any
as the type for its first argumentres
. Now the types are specified toFastifyReply
(orFastifyReply
|TRawResponse
if native response is allowed) :reply
,status
,render
,redirect
,setHeader
,getRequestHostname
,getRequestMethod
,getRequestUrl
.The following changes are breaking: some come from changes within Fastify itself; others are package cleanup.
The following functions originally took in variadic arguments of type
any
. They're now changed into the same signature as the Fastify instance function with the same name:register
,inject
,The following functions originally took additional arguments that were not used. These arguments are now removed:
setErrorHandler
,setNotFoundHandler
,initHttpServer
.setViewEngine
originally typed its argument asany
. This is because the appropriate Fastify plugin invoked in this function takes in aPointOfViewOptions
argument, but in the base HTTP adapter, the functionsetViewEngine
takes in a string. So far I allow the argument type to bePointOfViewOptions | string
and then does a runtime check, throws error and exits if the argument type isstring
. This works though it's quite ugly: maybe something should be done on the base HTTP adapter level.