Firebase-处理NestJS框架内的云事件 [英] Firebase - Handle cloud events within NestJS Framework

查看:38
本文介绍了Firebase-处理NestJS框架内的云事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NestJS 作为我的后端框架和Firebase.

I'm using NestJS as my backend Framework and Firebase.

要在HTTP请求上将Nest与Firebase集成在一起,就像将nest的快速实例附加到Firebase一样简单:

To integrate Nest with Firebase on HTTP requests is simple as attaching the express instance of nest to Firebase:

const server: Express = express();

const bootstrap = async (expressInstance: Express) => {
  const app = await NestFactory.create(AppModule, expressInstance);
  await app.listen(3000);
  await app.init();
};

bootstrap(server);

exports.api = functions.https.onRequest(server);

但是其他Google功能(例如pubsub,firestore,auth等)呢?

But what about the other Google Functions (such as pubsub, firestore, auth, etc.)?

我正在构建一个订阅应用程序,我依靠 functions.pubsub 在每天结束时检查我应该收费哪些订阅.它需要编写我想使用NestJs编写的业务逻辑.

I'm building a subscription application, and I depend on functions.pubsub to check at the end of every day which subscriptions should I charge. It requires writing business logic that I want to write withing NestJs.

我正在尝试实现这样的内容(简而言之):

I'm trying to achieve something like this (in a nutshell):

functions.pubsub
    .topic('topic')
    .onPublish(app.getService(Service).method);

推荐答案

原来,我离解决方案很近.代替 getService ,我不得不使用 get ,就像这样:

Turns out I was very close to the solution. instead of getService, I had to use get, like so:

const bootstrap = async (expressInstance: Express) => {
  const app = await NestFactory.create(AppModule, expressInstance);
  await app.init();

  return app;
};

const main = bootstrap(server);

export const subscriptions = functions
  .pubsub
  .topic('cron-topic')
  .onPublish((context, message) => main.then(app => {
    return app.get(SubscribeService).initDailyCharges(context, message));
  });

这篇关于Firebase-处理NestJS框架内的云事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆