dougmoscrop / serverless-http

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda 🎉
Other
1.72k stars 166 forks source link

NestJS: first request always fails and watching files doesn't work #148

Open mcblum opened 4 years ago

mcblum commented 4 years ago

First request Always Fails Hi. I'm trying to use serverless-http with NestJS. I'm seeing a strange issue where serverless basically processes the first request before the app has bootstrapped, causing the first request to always return a 404. Subsequent requests work.

Here's my handler function:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app/app.module';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as serverless from 'serverless-http';
import * as express from 'express';

const server = express();

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

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

export const handler = serverless(server);

Watching Doesn't Seem to Work Another issue I'm seeing is that even though I see this in the console every time I make a change to the source files:

74 modules
Serverless: Watching for changes...

the app doesn't actually re-build, meaning the changes are not reflected.

Any idea why these two things may be happening?