【发布时间】:2020-09-05 15:07:57
【问题描述】:
我搜索了很多,但没有关于如何使用 Typeorm 和 express 设置 firebase 云功能。
我正在尝试使用 Express + Apollo 服务器 + TypeORM 构建一个 api 服务器,但是要使用 TypeORM 连接到数据库,我需要执行类似的操作
createConnection().then(async connection => {
// init server here
app = express()
...
})
但要部署到 Firebase,我必须这样做
export const server = functions.https.onRequest(app)
我该如何组合这些?
也许我能做到
export const server = functions.https.onRequest(async (req, res) => {
createConnection().then(async connection => {
// init server here
app = express()
...
})
})
但是由于是Cloud Function,所以每次请求来,都会创建一个新的实例,也就是创建一个新的连接。这个可以吗?不会有速度问题吗?
更新
import { connect } from './config';
const app = express()
export const server = functions.https.onRequest(async (req, res) => {
const connection = await connect();
return app(req, res)
})
【问题讨论】:
标签: node.js firebase express google-cloud-functions typeorm