无法部署 firebase 云功能

Can't deploy firebase cloud function

我正在尝试使用 cors 部署 firebase 云函数,但它不起作用。这是我的代码,有人可以帮我吗?

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import * as cors from 'cors'

admin.initializeApp()

const corsHandler = cors({origin: true})

export const getUser = functions.https.onRequest((request, response) => {

    corsHandler(request, response, () => {})

    admin.firestore().doc("profiles/T0XCPHPkrJM4I10okb9KSHyukqn1").get()
    .then(snapshot => {
        const data = snapshot.data()
        console.log(data)
        response.send(data)
    })
    .catch(error => {
        console.log(error)
        response.status(500).send(error)
    })

})

以下应该有效。您必须将异步 Firebase 调用的代码 包含在 函数中。

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import * as cors from 'cors'

admin.initializeApp()

const corsHandler = cors({origin: true})

export const getUser = functions.https.onRequest((request, response) => {

    corsHandler(request, response, () => {

        admin.firestore().doc("profiles/T0XCPHPkrJM4I10okb9KSHyukqn1").get()
        .then(snapshot => {
            const data = snapshot.data()
            console.log(data)
            response.send(data)
        })
        .catch(error => {
            console.log(error)
          response.status(500).send(error)
        })

    })

})