0
votes

I am using NestJS and Cloud Functions, because of performance I want to switch to Fastify.

But I have no idea what to pass to functions.https.onRequest(???)

My old code for express is:

admin.initializeApp(functions.config().firebase);

const server: express.Express = express();

const startNestApplication = async (expressInstance: express.Express) => {
  const adapter = new ExpressAdapter(expressInstance);
  const app = await NestFactory.create(AppModule, adapter, {});
  app.enableCors();
  await app.init();
  return app;
};

const main = startNestApplication(server);

export const api = functions.https.onRequest(server);

And new code is:

admin.initializeApp(functions.config().firebase);

const startNestApplication = async () => {
  const adapter = new FastifyAdapter();
  const app = await NestFactory.create<NestFastifyApplication>(AppModule, adapter, {});
  app.enableCors();
  await app.init();
  return app;
};

const main = startNestApplication();

export const api = functions.https.onRequest(???);

https://docs.nestjs.com/techniques/performance

1
If Fastify doesn't somehow integrate with an express app as your first code sample shows, then there is not just a simple argument to pass here. You will have to build an express app to wrap it. - Doug Stevenson

1 Answers

0
votes

You will need to create an anonymous function to pass as an argument as specified in here[1].

[1] https://firebase.google.com/docs/functions/http-events