I've a project with polymer 2.0 web app with polymerfire and published to firebase hosting using firebase deploy
I've another project with a cloud function that acts on database trigger, and deployed it using firebase deploy --only functions:updateOnChange
I've another project with a cloud function that is an express app with route mappings GET /fns/register
, POST /fns/register
, and PUT /fns/register/confirm
. I've deployed this using firebase deploy --only functions:register
I've created the rewrite rules to map the routes /fns/**
to the register cloud function in my first project (the polymer one) in the firebase.json file. I see this as a current firebase limitation that we can't manage the rewrite rules from multiple projects.
Following is my firebase.json
in the 1st project (polymer project):
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "build/default/public",
"rewrites": [
{
"source": "/fns/**",
"function": "fns"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Now my requests for /fns/register
are getting routed to my register
cloud function, but the res.sendFile
I wrote in the app is not working. it always says
TypeError: path must be absolute or specify root to res.sendFile
at ServerResponse.sendFile (/user_code/node_modules/express/lib/response.js:410:11)
at app.get (/user_code/index.js:28:13)
at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)
at next (/user_code/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/user_code/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/user_code/node_modules/express/lib/router/layer.js:95:5)
at /user_code/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/user_code/node_modules/express/lib/router/index.js:335:12)
at next (/user_code/node_modules/express/lib/router/index.js:275:10)
at expressInit (/user_code/node_modules/express/lib/middleware/init.js:40:5)
My log statements inside the code are not working and even if I am sending simple res.send(JSON.stringify({ a: 1 }, null, 3));
it still throws the same above error.
This means, my code is not getting executed or my libraries are not getting uploaded to my cloud function. I want to understand the deployment scoping/ architecture/ dependencies of the cloud functions vs the app.
In Google IO 2017, the repeated advice was to go and use microsrevice style of development for the apps, and not a single monolith. What I am following here is microservice style of development, but getting no where!
Kindly help me here.
The issue I faced was not directly from firebase or its routing. The issue was with my express app configuration. I fixed the same and it all worked fine.
Moreover, I've created microservices (cloud functions) from multiple projects and been able to deploy them independently using the firebase deploy --only functions:fun1,fun2
and the scoping seem to work just fine. I've been using different version of the js libraries in different microservices and I didn't face any conflicts as of now!
Though I don't know the internals of the firebase deployment strategies. I could assert from my experience so far that, each deployment of the microservices are somehow sandboxed so that the other microservice projects have no conflict!
Only glitch is that the routing need to be handled in one single project, and this is understandable because of the complexity of maintaining multiple routing rules and possible collisions if they support the re-write rules be supported from multiple projects.
Someone with more insightful knowledge may correct my understanding.