I am having some trouble with converting Nestjs to serverless. My tech stack is, Nestjs, Graphql and Prisma. I have followed multiple guide buy to no avail, below are the tutorials I have follow. https://nishabe.medium.com/nestjs-serverless-lambda-aws-in-shortest-steps-e914300faed5 https://github.com/lnmunhoz/nestjs-graphql-serverless
The error that i am facing. It happens when i start to navigate to it. Example, http://localhost:3000/dev/graphql, I wanted to access the playground
The problem shows that serverless file is missing, but its there under src
This is my serverless.ts file inside src folder
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import { Context, Handler } from 'aws-lambda';
import serverless from 'aws-serverless-express';
import express from 'express';
import { Server } from 'http';
import { AppModule } from './app.module';
export async function bootstrap() {
const expressApp = express();
const adapter = new ExpressAdapter(expressApp);
const app = await NestFactory.create(AppModule, adapter);
await app.init();
return serverless.createServer(expressApp);
}
let cachedServer: Server;
export const handler: Handler = async (event: any, context: Context) => {
if (!cachedServer) {
const server = await bootstrap();
cachedServer = server;
return serverless.proxy(server, event, context);
} else {
return serverless.proxy(cachedServer, event, context);
}
};
And this is my serverless.yml file
service: laundry-api
provider:
name: aws
runtime: nodejs12.x
region: ap-southeast-1
stage: dev
profile: default # Config your AWS Profile
plugins:
- serverless-offline
functions:
index:
handler: src/serverless.handler
environment:
SLS_DEBUG: true
events:
- http:
path: graphql
method: any
cors: true
I have been cracking my head for hours on where is the problem, tried webpack too. Would be greate if you guys can point me to the right direction Thank you.