感谢 Doug Stevenson 的回答和帮助。不过我想提供我自己的答案。
所以一般来说,我的问题的答案是:不,你不能。
正如 Doug 所指出的,这对于许多人的扩展需求来说不是问题。 Firebase 将创建多达 1,000 个函数实例以进行扩展。
我想提供一个与 Doug 略有不同的答案,即我将如何编写 Express 应用程序并为项目提供不同的 Firebase 云功能:
const payment = express()
const order = express()
payment.get('/route', ...)
order.get('/route', ...)
export const payment = functions.https.onRequest(payment)
export const order = functions.https.onRequest(order)
这里的好处是我可以开始表达 REST 或 RPC 路由,例如:
- /payment/someaction (RPC)
- /order(获取、放置、发布等)
另一个好处是我可以为信用卡支付/处理等事情提供“测试”API 和“实时”API:
// [START Express LIVE App]
// [START get user]
app.get('/user', async (req, res) => {
await handleGetUser(req, res, paymentServiceLive);
});
// [END get user]
// [START claim]
app.post('/claim', async (req, res) => {
await handleClaim(req, res, claimEmailTo);
});
// [END claim]
// [START user]
app.post('/user', async (req, res) => {
await handleUserPost(req, res, paymentServiceLive);
});
// [END user]
// [START ephemeralKey]
app.post('/ephemeralKey', async (req, res) => {
await handleEphemeralKey(req, res, paymentServiceLive);
});
// [END ephemeralKey]
// [START charge]
app.post('/charge', async (req, res) => {
await handleCharge(req, res, paymentServiceLive);
});
// [END charge]
// [START purchase]
app.post('/purchase', async (req, res) => {
await handlePurchase(req, res, paymentServiceLive);
});
// [END purchase]
//Expose Express API as a single Cloud Function:
exports.app = functions.https.onRequest(app);
// [END Express LIVE App]
// [START Express TEST App]
// [START get user]
appTest.get('/user', async (req, res) => {
console.log('appTest /user get', req);
await handleGetUser(req, res, paymentServiceTest);
});
// [END get user]
// [START claim]
appTest.post('/claim', async (req, res) => {
await handleClaim(req, res, claimEmailToTest, true);
});
// [END claim]
// [START user]
appTest.post('/user', async (req, res) => {
console.log('appTest /user post', req);
await handleUserPost(req, res, paymentServiceTest);
});
// [END user]
// [START ephemeralKey]
appTest.post('/ephemeralKey', async (req, res) => {
await handleEphemeralKey(req, res, paymentServiceTest)
});
// [END ephemeralKey]
// [START charge]
appTest.post('/charge', async (req, res) => {
await handleCharge(req, res, stripeTest);
});
// [END charge]
// [START purchase]
appTest.post('/purchase', async (req, res) => {
await handlePurchase(req, res, paymentServiceTest);
});
// [END purchase]
//Expose Express API as a single Cloud Function:np
exports.apptest = functions.https.onRequest(appTest);
// [END Express TEST App]
这让我有一个开发环境和一个直播环境。在我的应用配置文件中,我只有一个不同的 API url:
/us-central1/apptest
或
/us-central1/app