Firebase云功能添加第二个项目

时间:2018-09-22 16:59:11

标签: firebase firebase-realtime-database google-cloud-functions firebase-admin

我正在使用Firebase实时数据库和云功能。对于我的第一个项目,它运行良好。现在,我想将云功能用于第二个项目,该项目也使用Firebase实时数据库。 我的问题:

  1. 我是否必须在同一index.ts文件中添加代码?
  2. 什么是最好的正确方法?
  3. 我从firebase doc找到了一些信息,我可以按照它说的去做吗?我对此很困惑。 enter image description here

在这里,我的代码在index.ts中

    import * as functions from 'firebase-functions';

        var admin = require("firebase-admin")

                admin.initializeApp({
                    credential: admin.credential.cert({
                        "type": "service_account",
                        "project_id": "qpoden-6873241b

d",
                    "private_key_id": "b44b18berewrewreqrewqrewqrewq",
                    "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqrewqrewqrOwtMeLaS0N18LrVO1v5NzvpDvqtvTDLBl1sS1\nKhR4WZhENA4SURj0+mAnKiNXTu9Nq1g0Xm6wZxDssu9pblzrzXg00zCbBGQxdnus\ngpXjBj8gdBGqVrKAo1Nb+Z2Luz4Q5kG3OMPSrewqrqrewLHRskf+k1A5CA362pMCbM/G/auOvwY7mU89aR8V/Dm5H29u7Yb09\nA5SDLsspAEgVCe938adiET/g8pq638eLSmXckf93nbY5IPw1Nq8Tg4PVEidPSPky\nHVCJlCoPXFJtsmc0VbxmEtPsBQKBgQDMQzC7DA9PRp8BzrOwmaKripqhqRRPQpjA\n/ggBEDKt5hVNVG6VGUU4Cr/x2kkS0ZdhuMrex606ZlFljfCaBuvJ1kknjV8T7Eix\nIsDEJsiZtH79RUZmamj/eQCxb6r+d+Wpx1shdQGjpmOvVjRCyoFJF/IlgHhY+ZP1\n+riJof666wKBgQCCn1zUk32bPM9bqch0m2/vK1Q8NVeFfskKjd+M3ckSZoKkz+aW\nnFLsS32uQIZGi5KGcNnigMuSTVOye9Z46n1icDm7WLQuWAKyjkSMx6QBpoVGUjEP\n6IlyxQc8Soi8gAYtKQywTP4fGvDNC/tHqOGyKIKpVj/l+ys5aobdYPKTvQKBgB4d\n/g5mPc+jiwhaMNZmIL0IR7p0UqFJIXq7OfTmLYLEfPmU7GUhf7o+o4SGeeXDb32i\nII9ug5Urxu6hWgtr39I3vTuOtakbWrB7fk6tpUA8g8jWMQYixG5+qeJ/o4e3p+47\nja1GMkKt4t7UaAo9D4j2deafpZ8A1ZccK59nekaXAoGABuw3GnyV7WIFUiL2tC2v\nW+/xEfM+mcvdE3E+NkB9wI+/bopZucY2MUZyGhMgom3JRnaVFJqNXcUINnZfSW89\nzrwelkOpal24RIPyBVN0L1e81+6dl6x6R948EaCwTPESzNX5jQsUJuuNfX4jKhIo\nmEweKwAsUm/HcWDUHD097qI=\n-----END PRIVATE KEY-----\n",
                    "client_email": "firebfsdgfssgfgsgfdsgdfsm",
                    "client_id": "1151561632443241342143243287",
                    "auth_uri": "https://accounts.google.cwqromewqr/orewq/rewqroauth2/autrewreqh",
                    "token_uri": "https://oauth2rewq.googrewleapis.com/torewqken",
                    "auth_provrewqider_xrewqrewqt502349_ce2344432rt_url": "https://www.googleapi32s.c24om/oa43uth24324/v4321/43243certs",
                    "client_x50432erwefds9_cert_41url": "https://www.googleapis.rewqco3rewm/rob3424ot/v1/meqrewqtadatwqa/x50rew9/fiewqewrebase-adminsdk-xy7hg%40rwqerqpon-687bd.iam.gservicewrwqrqweaccount.com"
                }),
                databaseURL: "https://fdasofsfggsn-6845547bd.firebaseio.com"
            });

    export const onMessgaeDetele = functions.database
    .ref('/Qpon/{country}/{city}/{nodeID}')
    .onDelete((snapshot, context) => {

        const getCountry = context.params.country
        const getCity = context.params.city
        const getNode = context.params.nodeID

        const y = snapshot.val()
        console.log(`Counrty - ${getCountry}, City - ${getCity}, node - ${getNode}, ${y}`)

        return snapshot.ref.parent.child('OUT').child(getNode).set(y)
    });

0 个答案:

没有答案