代码之家  ›  专栏  ›  技术社区  ›  xiaolingxiao

重构firebase function index.ts代码,以便可以导入触发器

  •  0
  • xiaolingxiao  · 技术社区  · 7 年前

    我正在用 https , auth datastore 触发器,所以我想把它们放到不同的文件中。我已经计算出 HTTPS 功能,但我不确定如何将 奥思 功能。我的 index.ts 目前:

    import * as express     from 'express';
    import * as functions   from 'firebase-functions';
    import  { spiceAdmin  } from './base';
    import  { spiceServer } from './spiceServer'
    
    import  { server }      from './api-routes/api'
    
    
    exports.app = functions.https.onRequest(server);
    
    
    
    /**
        @Use: send verification email on new user creation
    */
    exports.onCreate = functions.auth.user().onCreate( user => {
    
        spiceAdmin.auth().createUser({
              email         : 'user-auth-ts@gmail.com'
            , emailVerified : false
            , password      : 'Sup3rSafe'
        }) 
        .then((userRecord : any) => console.log('created new user'))
        .catch((err : string) => console.log(`failed to create new user with ${err}`))
    
    });
    

    特别是,如果我有档案 user_auth.ts 有触发器 onCreate onChange ,我怎么会 句法上 编写这些函数,然后导出,然后 exports.... 他们在 index.ts?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Doug Stevenson    7 年前

    索引文件

    import { myFunction } from './myfunction'
    export const myFunction_export = myFunction
    

    我的函数.ts

    import * as functions from 'firebase-functions'
    export const myFunction = functions.firestore.document(...).onCreate(...)