Repository navigation
feat: support Next.js API and NestJS responses - #9
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last open roadmap item: direct support for Next.js API and NestJS response objects in
withResponse(),.response()andServerResponse.Next.js
NextApiResponseLiketype, withresponse()andServerResponseoverloads. Resora sends throughres.status()/res.send()and reads the status text fromres.statusMessage. A{ req, res }context also gives Resora the request path for pagination links.Responseand have no mutable response object, soServerResponsegetstoWebResponse(). It resolves asyncdata(), runsbeforeSendhooks, and returns a JSONResponsewith the body, status, status text and headers.Content-Typedefaults toapplication/json.NestJS
Nest's
@Res()response is already an Expressresor a Fastifyreply, which Resora supports. This adds aNestHttpHostLiketype so anArgumentsHostorExecutionContext(from interceptors, guards and exception filters) works as the response or the context:extractResponseFromCtxandextractRequestUrlread the response and request fromswitchToHttp().resolveRawResponseunwraps a host passed to.response(host).response(host: NestHttpHostLike)overloads onResource,ResourceCollectionandGenericResource.Docs
toWebResponse()in the ServerResponse guide and API page.Tests
tests/nextjs.spec.ts: Pages Router routes run on a Node handler that addsstatus(),send()andjson()like Next does; App Router tests checktoWebResponse().tests/nestjs.spec.ts: a host shaped like Nest'sExecutionContextHostover Express and Fastify.These don't install
nextor@nestjs/*; they use the same shapes those frameworks pass in.pnpm test(234 passed),pnpm lintandpnpm buildpass.