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 ...

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.