-
-
Notifications
You must be signed in to change notification settings - Fork 37
updates readme for nestjs #142
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,6 +78,126 @@ When you execute your Fastify application like always, | |||||||||||||||||||||||||
| i.e. `node app.js` *(the detection for this could be `require.main === module`)*, | ||||||||||||||||||||||||||
| you can normally listen to your port, so you can still run your Fastify function locally. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Usage with NestJS | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ### main.ts | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||
| import { NestFactory } from '@nestjs/core'; | ||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||
| FastifyAdapter, | ||||||||||||||||||||||||||
| NestFastifyApplication, | ||||||||||||||||||||||||||
| } from '@nestjs/platform-fastify'; | ||||||||||||||||||||||||||
| import { AppModule } from './app.module'; | ||||||||||||||||||||||||||
| import awsLambdaFastify, { PromiseHandler } from '@fastify/aws-lambda'; | ||||||||||||||||||||||||||
| import fastify, { FastifyInstance, FastifyServerOptions } from 'fastify'; | ||||||||||||||||||||||||||
| import { Context, APIGatewayProxyEvent } from 'aws-lambda'; | ||||||||||||||||||||||||||
| import { Logger } from '@nestjs/common'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| interface NestApp { | ||||||||||||||||||||||||||
| app: NestFastifyApplication; | ||||||||||||||||||||||||||
| instance: FastifyInstance; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let cachedNestApp; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async function bootstrapServer(): Promise { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| async function bootstrapServer(): Promise { | |
| async function bootstrapServer(): Promise<NestApp> { |
Copilot
AI
Feb 4, 2026
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.
Using == for comparison is not recommended in TypeScript/JavaScript. Use strict equality === instead: (process.env.LOGGER || '0') === '1'.
| logger: (process.env.LOGGER || '0') == '1', | |
| logger: (process.env.LOGGER || '0') === '1', |
Copilot
AI
Feb 4, 2026
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 package fastify-cors has been deprecated and replaced with @fastify/cors. The code should use the newer package instead. Update the line to use @fastify/cors and consider importing it at the top of the file rather than using require() inline, which would be more consistent with the TypeScript imports used elsewhere in the example.
Copilot
AI
Feb 4, 2026
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 return type Promise<PromiseHandler> appears to be incorrect. The PromiseHandler type from @fastify/aws-lambda represents the handler function type, not the return value of the handler. The handler should return the actual response from the lambda proxy, which is typically something like Promise<APIGatewayProxyResult>. Consider removing the explicit return type or using the correct return type.
| ): Promise<PromiseHandler> => { | |
| ) => { |
Copilot
AI
Feb 4, 2026
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 function being called is bootstrap() but the function defined above is named bootstrapServer(). This is a critical bug that would prevent the code from working. The call should be changed to bootstrapServer().
| const nestApp = await bootstrap(); | |
| const nestApp = await bootstrapServer(); |
Copilot
AI
Feb 4, 2026
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.
There's a spelling error: "acheive" should be "achieve".
| In addition to the above, when using NestJS with GraphQL in a lambda environment, you will need to copy your `schema.gql` into your `dist` folder rather than relying on the `autoSchemaFile` option since this tries to write to `/src` directory inside a running lambda function and you are only allowed to write to `/tmp` directory. You can modify your build script in your `package.json` to acheive this: | |
| In addition to the above, when using NestJS with GraphQL in a lambda environment, you will need to copy your `schema.gql` into your `dist` folder rather than relying on the `autoSchemaFile` option since this tries to write to `/src` directory inside a running lambda function and you are only allowed to write to `/tmp` directory. You can modify your build script in your `package.json` to achieve this: |
Copilot
AI
Feb 4, 2026
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 app.module.ts example is missing necessary import statements. At minimum, it should include imports for Module, GraphQLModule, MercuriusDriverConfig, GqlModuleOptions, MercuriusDriver, join, and any other referenced symbols like createXYZLoader, XYZService, XYZModule, AppController, and AppService. Without these imports, the code example cannot be used as-is.
| ```typescript | |
| ```typescript | |
| import { Module } from '@nestjs/common'; | |
| import { GraphQLModule, GqlModuleOptions } from '@nestjs/graphql'; | |
| import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius'; | |
| import { join } from 'path'; | |
| import { createXYZLoader } from './xyz.loader'; | |
| import { XYZService } from './xyz.service'; | |
| import { XYZModule } from './xyz.module'; | |
| import { AppController } from './app.controller'; | |
| import { AppService } from './app.service'; |
Copilot
AI
Feb 4, 2026
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 code example is incomplete and missing the class decorator and export. The example should start with export class AppModule {} to be a complete and valid TypeScript class definition.
| }) | |
| }) | |
| export class AppModule {} |
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 variable
cachedNestAppis missing a type annotation. It should be typed to match whatawsLambdaFastifyreturns. Consider adding a type annotation such aslet cachedNestApp: PromiseHandler | undefined;orlet cachedNestApp: any;for clarity.