【发布时间】:2020-12-28 15:19:21
【问题描述】:
最近我通过参考another SO post 来构建我的firebase 函数,以便目录具有更加模块化的方法。
因此firebase目录结构是
index.js
|
modules/
├── enterprise
│ ├── getCompanyLicenseUsers.js
│ ├── index.js
│ └── revokeLicense.js
├── premium
│ ├── applyLicense.js
│ ├── getCouponDiscount.js
│ ├── index.js
│ ├── processPaypalPayment.js
│ └── unlockPremium.js
└── utils
├── index.js
└── utilityFunctions.js
不同模块中的所有文件(utils 除外)都单独导出为最上面的 index.js 中的 firebase 函数。每个模块的 index.js 都会对每个函数进行全局导出。
示例函数 getCompanyLicenseUsers
require('../utils');
const functions = require("firebase-functions");
module.exports.getCompanyLicenseUsers = () => {
return functions.https.onCall((data, context) => {
// function code
})
}
index.js 的模块,该函数是其中的一部分
global.getCompanyLicenseUsers = require('./getCompanyLicenseUsers').getCompanyLicenseUsers
global.revokeLicense = require('./revokeLicense').revokeLicense
主(最外层)index.js
// Module imports
require('./modules/enterprise')
require('./modules/notifications')
require('./modules/premium')
require('./modules/jobs')
// exporting firebase functions
exports.getCompanyLicenseUsers = getCompanyLicenseUsers();
exports.revokeLicense = revokeLicense();
exports.applyLicense = applyLicense();
exports.getCouponDiscount = getCouponDiscount();
exports.processPaypalPayment = processPaypalPayment();
exports.unlockPremium = unlockPremium();
现在我想添加另一个模块,但不是该模块的所有功能都需要导出。这些未导出的函数被导入到将从该模块导出的函数中。
我能够成功部署该函数,但是每当在 firebase 上执行此导出函数时,在导出函数内部调用但未显式导出到 firebase 的函数都会出现引用错误(但它们是其中的一部分导出函数的模块)。
我想我可以将这些单独的功能作为它们自己的模块,但我不想这样做,因为这样代码看起来有点过度组织。
感谢您阅读整个问题,如果您阅读了。非常感谢任何帮助
【问题讨论】:
标签: node.js firebase firebase-realtime-database google-cloud-functions