-
-
Notifications
You must be signed in to change notification settings - Fork 70
[WIP] Support Nestjs Integration #309
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @malkoG, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request initiates the development of a dedicated integration layer for the Fedify library with the NestJS framework. It establishes a new package containing a NestJS module for managing the Fedify Federation
instance and a middleware to bridge the request/response handling between NestJS's Express-based environment and Fedify's Web API expectations. This work-in-progress aims to provide a robust and idiomatic way to use Fedify within NestJS applications.
Highlights
- New NestJS Integration Package: This pull request introduces a brand new
@fedify/nestjs
package, designed to seamlessly integrate the Fedify library into NestJS applications. This marks a significant expansion of Fedify's compatibility with popular web frameworks. - Core NestJS Module (
FedifyModule
): A newFedifyModule
has been added, providing aforRoot
static method. This module allows NestJS applications to easily configure and provide aFederation
instance, managing its lifecycle and dependencies within the NestJS ecosystem. - Request/Response Adaptation Middleware: A key component is the
integrateFederation
middleware. This middleware handles the crucial task of converting standard ExpressRequest
andResponse
objects (used by NestJS) into Web APIRequest
andResponse
objects, which are required by Fedify'sfederation.fetch
method. It also maps Fedify's response back to Express. - Package Structure and Configuration: The PR includes all necessary files for the new package, such as
package.json
,deno.json
, andtsdown.config.ts
, setting up its build process, dependencies (including@nestjs/common
andexpress
), and export points. - Placeholder README Discrepancy: The
nestjs/README.md
file appears to be a placeholder copied directly from the@fedify/express
package. This README will need to be updated to accurately reflect the integration steps and usage for NestJS applications.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new package for NestJS integration with Fedify. The review focuses on improving the robustness of the middleware by streaming request and response bodies, and ensuring documentation and configuration are accurate.
nestjs/fedify.middleware.ts
Outdated
body: ['GET', 'HEAD'].includes(req.method) ? undefined : JSON.stringify(req.body), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The request body is being handled by serializing the request body (JSON.stringify(req.body)
), which is inefficient and may not work for non-JSON payloads. Stream the raw request body using Readable.toWeb(req)
from node:stream
.
const webRequest = new Request(url.toString(), {
method: req.method,
headers,
// @ts-ignore: duplex is not supported in Deno, but it is in Node.js
duplex: "half",
body: ['GET', 'HEAD'].includes(req.method)
? undefined
: Readable.toWeb(req),
});
nestjs/fedify.middleware.ts
Outdated
const body = await response.text(); | ||
res.send(body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response is buffered using await response.text()
, which can lead to high memory usage for large responses. Stream the response body directly to the client by iterating over response.body
's ReadableStream
and writing each chunk to the Express response.
res.status(response.status);
if (response.body) {
for await (const chunk of response.body) {
res.write(chunk);
}
}
res.end();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
nestjs/deno.json
Outdated
}, | ||
"imports": { | ||
"express": "npm:express@^4.0.0", | ||
"nestjs": "npm:@nestjs/core@^11.0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for this pull request have been published: |
Specify dependency for @nestjs/common
Fix lint error
I am facing this error. Investigating...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have some tests as well?
nestjs/fedify.middleware.ts
Outdated
const body = await response.text(); | ||
res.send(body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
Wait. I am facing this error. I will resolve it.
|
The latest push to this pull request has been published to JSR and npm as a pre-release:
|
Summary
closes: #269
Support NestJS integration
Benefits
NestJS Developers who want to develop fediverse app, They can easily build ActivityPub app thanks to Fedify
Checklist
deno task test-all
on your machine?