【发布时间】:2021-02-24 21:22:42
【问题描述】:
在this official Firebase example 中描述了如何构建云功能以最大限度地减少冷启动时间。
主要思想在index.ts文件中似乎如下:
export const httpFn =
functions.https.onRequest(async (request, response) => {
await (await import('./fn/httpFn')).default(request, response)
})
换句话说,使用 await(await import())。然而,这个例子是在打字稿中。这在 node.js 中看起来如何?我找到了一些例子。例如。 this one.
其中 index.js 文件有:
exports.helloWorld = require('./hello-world').helloWorld
各个函数文件如下所示:
const functions = require('firebase-functions')
exports.helloWorld = functions.https.onRequest((request, response) => {
const output = {
di: 'is cool',
}
response.send(output)
})
这是在 node.js 中最小化冷启动时间的最佳方法吗?鉴于我不能使用“等待导入”。这个结构是否只会为每个单独的函数加载必要的依赖项?或者它是否仍会加载所有必需(导入)文件的所有依赖项?
【问题讨论】:
标签: javascript firebase google-cloud-functions