Skip to content

Instantly share code, notes, and snippets.

@DesmondFox
Created September 3, 2023 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DesmondFox/b9a70c0f38d8c1a9e28f2bc54435a573 to your computer and use it in GitHub Desktop.
Save DesmondFox/b9a70c0f38d8c1a9e28f2bc54435a573 to your computer and use it in GitHub Desktop.
NestJS and SwaggerUI
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import * as express from 'express';
import * as functions from 'firebase-functions';
import { AppModule } from './src/app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
const expressServer = express();
const createFunction = async (expressInstance): Promise<void> => {
const app = await NestFactory.create(
AppModule,
new ExpressAdapter(expressInstance),
);
const config = new DocumentBuilder()
.setTitle('Hello world')
.setVersion('1.0')
.setDescription("Test description")
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('/app', app, document);
await app.init();
};
export const api = functions.https.onRequest(async (request, response) => {
await createFunction(expressServer);
expressServer(request, response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment