我在用着NestJS https://nestjs.com作为我的后端框架和 Firebase。
要在 HTTP 请求上将 Nest 与 Firebase 集成起来很简单,只需将 Nest 的 Express 实例附加到 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 等)呢?
我正在构建一个订阅应用程序,我依赖functions.pubsub
每天结束时检查我应该收取哪些订阅费。它需要编写我想用 NestJs 编写的业务逻辑。
我正在尝试实现这样的目标(简而言之):
functions.pubsub
.topic('topic')
.onPublish(app.getService(Service).method);
事实证明我非常接近解决方案。代替getService
,我不得不使用get
,像这样:
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));
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)