-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.ts
27 lines (25 loc) · 938 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 * as admin from 'firebase-admin';
import { ValidationPipe } from '@nestjs/common';
admin.initializeApp({
credential: admin.credential.cert(functions.config().todo_firebase_config),
databaseURL: 'https://todo-c9f6e-default-rtdb.firebaseio.com',
});
const expressServer = express();
const createFunction = async (expressInstance): Promise<void> => {
const app = await NestFactory.create(
AppModule,
new ExpressAdapter(expressInstance),
);
app.enableCors();
app.useGlobalPipes(new ValidationPipe());
await app.init();
};
export const api = functions.https.onRequest(async (request, response) => {
await createFunction(expressServer);
expressServer(request, response);
});