2

I am trying to add multiple firebase functions in the index.ts file following the example here: How do I structure Cloud Functions for Firebase to deploy multiple functions from multiple files?.

In particular, I have an express.js server which I initialized in routes.ts:

const server = express();
server.get('/api', (req, res) => res.send('hello /api'))
export {server}

Now In index.ts I can import routes.ts and also attach an user authentication listener so that when a new user is created, it fires, ie:

import {server} from './routers'

exports.app = functions.https.onRequest(server);
exports.userEvents = functions.auth.user().onCreate(user => {
    console.log("user created: ", user.email, user)
})

However so far as I can tell only exports.app is actually working as intended, and exports.userEvents seem to not fire on new user creation.

=========================================================

EDIT:

The problem is how my firebase.json function is set up, it currently only serve app with endpoints starting with /api/**, ie:

{
  "hosting": {
    "public": "public",

    // the problem is here: you're not connecting to multiple functions
    "rewrites": [{
        "source": "/api/**"
      , "function": "app"  



      }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
}

The questions is now how do I tell firebase to serve functions fromexports.userEvents ...

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
xiaolingxiao
  • 4,793
  • 5
  • 41
  • 88

1 Answers1

0

The problem is that I was trying to simulate the functions in local environment. I had to deploy them for the non http functions to run. However there is a local emulator for other functions described at the bottom of the doc: https://firebase.google.com/docs/functions/beta-v1-diff, which is new.

xiaolingxiao
  • 4,793
  • 5
  • 41
  • 88