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