nestjs / docs.nestjs.com

The official documentation https://docs.nestjs.com πŸ“•
MIT License
1.18k stars 1.68k forks source link

Serverless deploy #96

Closed kamilmysliwiec closed 3 years ago

kamilmysliwiec commented 6 years ago

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request (new chapter/page)
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

No docs

Expected behavior

I would like to see GCP/AWS/Azure (basically serverless) documentation.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


For Tooling issues:
- Node version: XX  
- Platform:  

Others:

samdelagarza commented 6 years ago

+1

samdelagarza commented 6 years ago

google cloud, or aws lambda, azure functions...

simonpeters commented 6 years ago

+1

dpapukchiev commented 6 years ago

+1

rdlabo commented 6 years ago

+1

rdlabo commented 6 years ago

I created repository how to use nestjs in serverless framework. I hope this will help. https://github.com/nestjs/nest/issues/238

rdlabo/serverless-nestjs https://github.com/rdlabo/serverless-nestjs

rynop commented 6 years ago

Cross post from #238, but don't want it to get buried in a closed issue...

For those of you looking to deploy to APIGateway (proxy+) + Lambda, I just figured it out (Thanks @brettstack for all your work). Took me some time to piece all the parts together, hope this helps someone else out.

lambda.ts:

require('source-map-support').install();

import { Context, Handler } from 'aws-lambda';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Server } from 'http';
import { createServer, proxy } from 'aws-serverless-express';
import { eventContext } from 'aws-serverless-express/middleware';
import express from 'express';

let cachedServer: Server;
const expressApp = require('express')();

// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by aws-serverless-express and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below
const binaryMimeTypes: string[] = [];

async function bootstrapServer(): Promise<Server> {
  const nestApp = await NestFactory.create(AppModule, expressApp);
  nestApp.use(eventContext());
  await nestApp.init();
  return createServer(expressApp, undefined, binaryMimeTypes);
}

export const handler: Handler = async (event: any, context: Context) => {
  if (!cachedServer) {
    console.log('Bootstraping server');
    cachedServer = await bootstrapServer();
  } else {
    console.log('Using cached server');
  }
  return proxy(cachedServer, event, context, 'PROMISE').promise;
};

For extra credit, you can add the following to your package.json's scripts to reduce the size of your zip file prior to deploy. If someone knows of an npm module to only include the code in node_modules that typescript needs I'd appreciate it:

"package": "rm /tmp/lambda.zip; zip -r /tmp/lambda.zip dist node_modules -x 'node_modules/typescript/*' 'node_modules/@types/*'"
jmpreston commented 5 years ago

@rynop, I'm exploring using AWS Lambda with Nestjs. Where does your code go? In each Lambda function? Or does code in Lambda call it from an EC2 server with each Lambda call? Or some other setup?

neilime commented 5 years ago

I have build an API powered by NestJs, and serverless (https://github.com/serverless/serverless) hosted on lambda.

It runs in production.

What I have done :

A single one handler (endpoint) /api/v1/{proxy+} redirect to the nestjs app.

For performance reasons, the handler is caching :

To avoid preflight CORS requests, I choose to only accept only GET, HEAD, POST requests whith text/plain Content-Type.


I think I can improve performance by using fastify instead of express, but I don't manage it for the moment

jmpreston commented 5 years ago

Lambda layers is the way to go now. I haven't spent time trying to figure out how this works yet. We need a good blog post on this. I'm not advanced enough for that.

dylandechant commented 5 years ago

also interested in this

rynop commented 5 years ago

@svstartuplab @dylandechant I built an open source project called https://github.com/rynop/aws-blueprint that is an easy to use CI/CD driven blueprint you can use to drive production grade applications.

In the examples section, check out the abp-single-lambda-api. It will do everything you need to run a NodeJs based app. While I don't have an explicit NestJs example, my comment above from 8/22 should be a copy/paste replacement for the typescript example handler (just replace contents of this file with my post above).

aws-blueprint does too many things to cover in this post, however I think once you give it a try and get over the small learning curve, you will see it really gives you alot (ex: @neilime everything you mention aws-blueprint gives you for "free" - plus MUCH more).

Last - if you need to talk to a RDS DB or need to communicate to resources in a VPC (ex Mongo cluster), I'd save yourself some time and NOT use Lambda with NestJs (or any API for that matter). The ENI attachments cause killer cold starts. Instead I'd use fargate - aws-blueprint has a nice blueprint for it (see abp-fargate in the Examples section).

jmpreston commented 5 years ago

@rynop I'm a single dev and don't want to get into CI/CD or containers. Either just Ubuntu as setup on my dev machine and just deploy to AWS EC2 or API Gateway and Lambda. I already have Postgres setup on RDS. My current app won't have much traffic, at least for a while.

So Lambda Layers is interesting to me. I'm trying to figure out how to setup Layers with Nestjs. So far it is difficult to find a good blog post or docs on this. I have Nestjs / REST working well in dev but don't have the Lambda concept with it worked out yet. Also exploring GraphQL.

rynop commented 5 years ago

I don't know much about Layers yet, but my initial read was it is overly complex. Hence I haven't set aside time to investigate.

rdlabo commented 5 years ago

Updated rdlabo/serverless-nestjs to nestjs6, and add environment for swagger. I hope this will help.

rdlabo/serverless-nestjs https://github.com/rdlabo/serverless-nestjs

Can-Sahin commented 5 years ago

I used Nestjs in a free time project I made. Its fully serverless with DynamoDB, DynamoDB Streams, S3 triggers etc... You can see my way of using Nestjs and deploying to AWS if you are looking for an example. Also includes Lambda with webpack

https://github.com/International-Slackline-Association/Rankings-Backend

related with nestjs/nest#238

cctoni commented 5 years ago

Please have a look into deploying nestjs to now.sh, would be great!

vfrank66 commented 5 years ago

I found this package for AWS Lambda/API Gateway, using methods above with nestjs fastify:

https://github.com/benMain/aws-serverless-fastify

lnmunhoz commented 5 years ago

For a few days I was trying to use @nestjs/graphql with the serverless approach, after a few tries I came up with a solution that worked well.

If you are looking for nestjs + graphql + code-first on aws lambda, this example might be useful for you. I am using in production πŸ‘

Repository: https://github.com/lnmunhoz/nestjs-graphql-serverless

kamilmysliwiec commented 5 years ago

We have recently published an article about Nest + Zeit Now deployment cc @MarkPieszak https://trilon.io/blog/deploying-nestjs-to-zeit-now

samdelagarza commented 5 years ago

Thanks! That’s great. Any plans on aws lambda?

Sam

On Jul 31, 2019, at 9:27 AM, Kamil Mysliwiec notifications@github.com wrote:

We have recently published an article about Nest + Zeit Now deployment cc @MarkPieszak https://trilon.io/blog/deploying-nestjs-to-zeit-now

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

murraybauer commented 5 years ago

I saw on Twitter a few days ago an annoucement for an offical Nest Schematic for Azure Functions:

Can add via nest add @nestjs/azure-func-http schematic

Uses azure-express behind the schemes: https://github.com/nestjs/azure-func-http/blob/885fb33c109ed2a0b59c97fe0912bf412bf2228e/lib/azure-http.adapter.ts

rynop commented 5 years ago

I have a new blueprint that contains a working example of NestJS (using Fastify engine) with API Gateway to Lamba. CI/CD driven deploys. Local APIG+Lamba and DyanmoDB local support. https://github.com/rynop/abp-sam-nestjs

@kamilmysliwiec I think NestJS app running behind API Gateway and in Lambda is a pretty compelling/powerful use case. I'm happy to do the work to document how to do this but:

Is this something you want documented in the official docs? If yes: where and I'll work on a PR.

If no:

Not just trying to get notoriety for my repo. The concept is not super straight forward, and IMO should be an entity that evolves on its own - updating best practices as AWS evolves...

"not a good fit for nestjs docs" is a fine answer too - wont hurt my feelings.

kop7 commented 5 years ago

any example how to deploy serverless nestjs with typeorm?

It should be simple???

I create CompanyModule in nest-serverless project with typeorm crud:

companyModule

@Module({
  imports: [TypeOrmModule.forFeature([Company])],
  controllers: [CompanyController],
  providers: [CompanyService],
})
export class CompanyModule {}

CompanyService

@Injectable()
export class CompanyService extends TypeOrmCrudService<Company> {
    constructor(
        @InjectRepository(Company)
        private readonly CompanyRepository: Repository<Company>) {
        super(CompanyRepository);
    }
}

CompanyEntity

@Entity('company')
export class Company {
    @PrimaryGeneratedColumn()
    id: number;
    @Column()
    name: string;
}

CompanyController

@Crud({model: {
        type: Company,
    }})
@Controller('api/company')
export class CompanyController implements CrudController<Company> {
    constructor(public readonly service: CompanyService) {}
}

AppModule:

@Module({
  imports: [
    TypeOrmModule.forRoot({
          type: 'mysql',
          host: 'x.x.x.x,
          port: 3306,
          username: 'xxxxx',
          password: 'xxxxx',
          database: 'xxxx',
          charset: 'utf8',
          logging: false,
          logger: 'advanced-console',
          entities: [__dirname + './../**/*.entity!(*.d).{ts,js}'],
          keepConnectionAlive: true,
          synchronize: true,
    }),
    CompanyModule,
  ],
  controllers: [ AppController],
  providers: [ AppService,],
})
export class AppModule { }

commad: rimraf dist && npm run build && sls deploy -s dev

Serverless: Optimize: starting engines
Serverless: Optimize: nestjs-restapi-dev-company
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service nestjs-restapi.zip file to S3 (6.71 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.........................................
Serverless: Stack update finished...
Service Information
service: nestjs-restapi
stage: dev
region: eu-central-1
stack: nestjs-restapi-dev
resources: 35
api keys:
  None
endpoints:
  ANY - https://xxxxxxxxxxxxx.execute-api.eu-central-1.amazonaws.com/dev/api/company

functions:
  company: nestjs-restapi-dev-company
layers:
  None
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.

Getting errors from Aws:


[Nest] 1 - 2019-08-27 08:09 [NestFactory] Starting Nest application...
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] TypeOrmModule dependencies initialized +91ms
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] PassportModule dependencies initialized +1ms
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] JwtModule dependencies initialized +1ms
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] AdsModule dependencies initialized +0ms
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 1 - 2019-08-27 08:09 [InstanceLoader] TypeOrmCoreModule dependencies initialized +77ms
[Nest] 1 - 2019-08-27 08:09 [ExceptionHandler] No repository for "Company" was found. Looks like this entity is not registered in current "default" connection? +1ms
RepositoryNotFoundError: No repository for "Company" was found. Looks like this entity is not registered in current "default" connection?
at new RepositoryNotFoundError (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:179054:28)
at EntityManager.getRepository (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:177032:19)
at Connection.getRepository (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:153557:29)
at getRepository (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:10232:26)
at InstanceWrapper.useFactory [as metatype] (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:10241:20)
at Injector.instantiateClass (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:4017:55)
at callback (/var/task/_optimize/nestjs-restapi-dev-company/dist/index.js:3812:41)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
kamilmysliwiec commented 5 years ago

We started working on articles:

More articles coming soon

kop7 commented 4 years ago

If someone is going to need it, there's an example:serverless-nestjs-typeorm

ripley commented 4 years ago

@rynop Would you elaborate a bit on how to handle the aws event proxied to the cached nest server?

I'm trying to implement an authorizer lambda with nestjs, the auth token is passed in as "authorizationToken" field in the event object from AWS API gateway.

Cross post from #238, but don't want it to get buried in a closed issue...

For those of you looking to deploy to APIGateway (proxy+) + Lambda, I just figured it out (Thanks @brettstack for all your work). Took me some time to piece all the parts together, hope this helps someone else out.

lambda.ts:

require('source-map-support').install();

import { Context, Handler } from 'aws-lambda';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Server } from 'http';
import { createServer, proxy } from 'aws-serverless-express';
import { eventContext } from 'aws-serverless-express/middleware';
import express from 'express';

let cachedServer: Server;
const expressApp = require('express')();

// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by aws-serverless-express and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below
const binaryMimeTypes: string[] = [];

async function bootstrapServer(): Promise<Server> {
  const nestApp = await NestFactory.create(AppModule, expressApp);
  nestApp.use(eventContext());
  await nestApp.init();
  return createServer(expressApp, undefined, binaryMimeTypes);
}

export const handler: Handler = async (event: any, context: Context) => {
  if (!cachedServer) {
    console.log('Bootstraping server');
    cachedServer = await bootstrapServer();
  } else {
    console.log('Using cached server');
  }
  return proxy(cachedServer, event, context, 'PROMISE').promise;
};

For extra credit, you can add the following to your package.json's scripts to reduce the size of your zip file prior to deploy. If someone knows of an npm module to only include the code in node_modules that typescript needs I'd appreciate it:

"package": "rm /tmp/lambda.zip; zip -r /tmp/lambda.zip dist node_modules -x 'node_modules/typescript/*' 'node_modules/@types/*'"
rynop commented 4 years ago

@ripley check out https://github.com/rynop/abp-sam-nestjs mentioned in my https://github.com/nestjs/docs.nestjs.com/issues/96#issuecomment-517283665 above. An example is in that repo @ https://github.com/rynop/abp-sam-nestjs/blob/master/src/apig-lambda.ts

vadistic commented 4 years ago

I've come up with something like this for Zeit Now @now/node builder.

Works with now GitHub CI / with cloud compilation - if I give up using tsconfig-paths

import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import { from } from 'rxjs';

import { AppModule } from './app.module';

async function bootstrap() {
  const instance = express();
  const adapter = new ExpressAdapter(instance);
  const app = await NestFactory.create(AppModule, adapter);

  await app.init();

  return instance;
}

// Observable for cold start
const server = from(bootstrap());

export default async function serverless(req, res) {
  const handler = await server.toPromise();

  return handler(req, res);
}
vadistic commented 4 years ago

Also did someone managed to get @nestjs/graphql on azure functions?

Zeit Now is blocked by this: https://github.com/zeit/now/issues/3115, so I wanted to try azure. Rest functions/ rests parts of nest apps are working fine, but I'm getting silent 204/timeous on graphql requests (both in func start & deployed). Whole app inits and works - just nothing is returned from GraphQLModule. No exceptions either.

I've tried all permutation of:

// function.json
   {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }

I'm runnig out of ideas. I would be glad to simply hear it's possible :smile:

jparneodo commented 4 years ago

@vadistic Do you solved your problem ? I am stuck also on same point.

To be sure of kinematic, I started with: set DEBUG=* & npm run start:azure

In file node_modules/@nestjs/azure-func-http/dist/azure-http.adapter.js line 16 return handler(context, req);

Returns undefined

Not sure but it doesn't seems to be a good value.

marekm1844 commented 4 years ago

'return proxy(cachedServer, event, context, 'PROMISE').promise;`

Today I had constant Error 502 from Api Gateway and could not figure out what is going on since Lambda logs were ok.

At the end the returning promise in proxy server saved the day and 502 Internal server error is gone !

karocksjoelee commented 4 years ago

I am wondering if someone thinks mapping NestJS controller to Serverless Lambda handler is a good idea ?

Basically I want local develop server can have Swagger document and can deploy each API end point as a Lambda function. Is this possible ?

marekm1844 commented 4 years ago

I am wondering if someone thinks mapping NestJS controller to Serverless Lambda handler is a good idea ?

Basically I want local develop server can have Swagger document and can deploy each API end point as a Lambda function. Is this possible ?

You can split into multiple functions with serverless and using direct path to controller instead of {proxy} but you would still need whole nestjs instance for each lambda to use shared stuff like guards, models etc.

vnenkpet commented 4 years ago

Is there any advice on how to run it with Google Cloud function? I think it should be pretty straightforward, but I can't figure out how should the exported function for google cloud look.

This is a default google cloud function:

export const helloWorld = (request, response) => {
  response.status(200).send("Hello World 2!");
};

I suppose I need to extract something like HttpServer or HttpAdapter from nest app instance and pass the request/response parameters to it, but I'm not sure on how to exactly do it.

The only issue about this that I could find https://github.com/nestjs/nest/issues/238 basically only answered for AWS for reasons I don't understand πŸ˜•

vnenkpet commented 4 years ago

Ok, I figured it out, for anyone who wants to run Nestjs with Google Cloud Functions (without Firebase), it's actually quire straightforward:

import { NestFactory } from "@nestjs/core";
import { ExpressAdapter } from "@nestjs/platform-express";
import { AppModule } from "./app.module";
import express from "express";

const server = express();

export const createNestServer = async expressInstance => {
  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance)
  );

  return app.init();
};

createNestServer(server)
  .then(v => console.log("Nest Ready"))
  .catch(err => console.error("Nest broken", err));

export const handler = server;

You can also add this to package.json to make the process a bit more straightforward:

  "main": "dist/handler.js",
  "scripts": {
    "gcp:start": "functions-framework --target=handler --port=8001",
    "gcp:watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run gcp:watch-ts\" \"npm run gcp:watch-node\"",
    "gcp:watch-node": "nodemon --watch dist --exec npm run gcp:start",
    "gcp:watch-ts": "nest build --watch",
    "gcp:deploy": "gcloud functions deploy handler --runtime nodejs10 --trigger-http"
 }

Of course you have to have concurrently, functions-framework etc. installed for this to run. Then just

npm run gcp:watch

to run it locally, and

npm run gcp:deploy

to deploy.

joffarex commented 4 years ago

Quick question: is it a good idea to run full api on lambda or any other similar service, which connects to db on basically every request?

kukuandroid commented 4 years ago

I have build an API powered by NestJs, and serverless (https://github.com/serverless/serverless) hosted on lambda.

It runs in production.

What I have done :

A single one handler (endpoint) /api/v1/{proxy+} redirect to the nestjs app.

For performance reasons, the handler is caching :

  • express App
  • Nestjs app
  • Mongodb connection

To avoid preflight CORS requests, I choose to only accept only GET, HEAD, POST requests whith text/plain Content-Type.

I think I can improve performance by using fastify instead of express, but I don't manage it for the moment

Hello, does the performance for monolith architecture is ok ? I'm thinking of implementing single-point access , do have you any examples ? Thank you

TreeMan360 commented 4 years ago

Hey all,

Since migrating to Nestjs 7 I am really struggling to get aws-serverless-express working. It was working absolutely fine on version 6 and it runs fine locally without the lambda.

I have tried an insane amount of different package version combinations but alas I still receive the following error:

ERROR TypeError: **express_1.default.Router is not a function at ApolloServer.getMiddleware** (/var/task/node_modules/apollo-server-express/dist/ApolloServer.js:81:42) at ApolloServer.applyMiddleware (/var/task/node_modules/apollo-server-express/dist/ApolloServer.js:76:22) at GraphQLModule.registerExpress (/var/task/node_modules/@nestjs/graphql/dist/graphql.module.js:119:22) at GraphQLModule.registerGqlServer (/var/task/node_modules/@nestjs/graphql/dist/graphql.module.js:103:18) at GraphQLModule.<anonymous> (/var/task/node_modules/@nestjs/graphql/dist/graphql.module.js:93:18) at Generator.next (<anonymous>) at fulfilled (/var/task/node_modules/tslib/tslib.js:110:62) at processTicksAndRejections (internal/process/task_queues.js:97:5)

I have wasted over a day on this now, so frustrating. Before going any further has anybody managed to get Nestjs 7 running on Lambda?

Thanks

hbthegreat commented 4 years ago

@TreeMan360 We have quite a few projects running on 6.9.0 and am yet to migrate to 7 but the error you are getting there looks it could be build related rather than nest version related. Are you using webpack by any chance? If you are I ran into this same issue with postgres and a few other platforms and was able to solve it with serverless-webpack forceIncludes. image

TreeMan360 commented 4 years ago

@hbthegreat Actually this was a bug in Serverless Framework Enterprise with the bug residing in the SDK that is automatically included for enterprise/pro customers to do instrumentation.

https://github.com/serverless/serverless/issues/7543 https://forum.serverless.com/t/highly-confusing-express-router-issue/10987

Everything is now working absolutely fine on nestjs 7 :)

hbthegreat commented 4 years ago

@TreeMan360 Great to hear you got a resolution!

danieldanielecki commented 4 years ago

Ok, I figured it out, for anyone who wants to run Nestjs with Google Cloud Functions (without Firebase), it's actually quire straightforward:

import { NestFactory } from "@nestjs/core";
import { ExpressAdapter } from "@nestjs/platform-express";
import { AppModule } from "./app.module";
import express from "express";

const server = express();

export const createNestServer = async expressInstance => {
  const app = await NestFactory.create(
    AppModule,
    new ExpressAdapter(expressInstance)
  );

  return app.init();
};

createNestServer(server)
  .then(v => console.log("Nest Ready"))
  .catch(err => console.error("Nest broken", err));

export const handler = server;

You can also add this to package.json to make the process a bit more straightforward:

  "main": "dist/handler.js",
  "scripts": {
    "gcp:start": "functions-framework --target=handler --port=8001",
    "gcp:watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run gcp:watch-ts\" \"npm run gcp:watch-node\"",
    "gcp:watch-node": "nodemon --watch dist --exec npm run gcp:start",
    "gcp:watch-ts": "nest build --watch",
    "gcp:deploy": "gcloud functions deploy handler --runtime nodejs10 --trigger-http"
 }

Of course you have to have concurrently, functions-framework etc. installed for this to run. Then just

npm run gcp:watch

to run it locally, and

npm run gcp:deploy

to deploy.

My setup was really similar for Firebase deployment, i.e.

import * as admin from 'firebase-admin';
import * as express from 'express';
import * as functions from 'firebase-functions';
import { ApplicationModule } from './app.module';
import { enableProdMode } from '@angular/core';
import { Express } from 'express';
import {
  ExpressAdapter,
  NestExpressApplication
} from '@nestjs/platform-express';
import { NestFactory } from '@nestjs/core';

enableProdMode(); // Faster server renders in production mode (development doesn't need it).
admin.initializeApp(); // Initialize Firebase SDK.
const expressApp: Express = express(); // Create Express instance.

(async () => {
  const nestApp = await NestFactory.create<NestExpressApplication>(
    ApplicationModule,
    new ExpressAdapter(expressApp)
  );
  nestApp.useStaticAssets(join(process.cwd(), 'dist/apps/my-app-browser'));
  nestApp.init();
})().catch(err => console.error(err));

// Firebase Cloud Function for Server Side Rendering (SSR).
exports.angularUniversalFunction = functions.https.onRequest(expressApp);