I want to deploy NestJS app on azure function via serverless framework. Need help to setup handler and serverless.yml for node 18 version
I tried below solution but didn't help.
import { Context, HttpRequest } from '@azure/functions';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
let cachedServer;
async function bootstrapServer(): Promise<any> {
const app = await NestFactory.create(AppModule);
await app.init();
return app.getHttpAdapter().getInstance();
}
export async function handler(context: Context, req: HttpRequest): Promise<void> {
if (!cachedServer) {
cachedServer = await bootstrapServer();
}
context.res = {
status: 200,
body: 'Serverless NestJS on Azure Functions!',
};
await cachedServer(context.req, context.res);
}
I have created a NestJs Azure function with below commands:
Local Response:
npm run buildbefore deploying the application to Azure.Portal:
References:
Deploy NestJS Serverless Apps to Azure Functions - Trilon Consulting