Reputation: 349
I've just used Express with Firebase Cloud Functions and made an endpoint.
app.get('/time', (req, res) => {
const date = new Date();
const hours = (date.getHours() % 12) + 1; // London is UTC + 1hr;
res.json({bongs: 'BONG '.repeat(hours)});
});
The endpoint is accessible publicly with the path:
https://<region>-<project-name>.cloudfunctions.net/app/time
where app is from entry source index.js:
exports.app = functions.region('asia-east2').https.onRequest(app);
However, it's not accessible with the path:
https://<project-name>.web.app/app/time
It requires me to grant the permission and select my Google account by default. How come? The endpoint is for public access.
Did I miss anything to setup and how to solve this problem?
If I don't use Express Framework, both the above 2 paths are accessible for public. (i.e. Call functions from your app, https://firebase.google.com/docs/functions/callable)
Thank you~
Upvotes: 4
Views: 1570
Reputation: 4126
The unaccessible path implies that you're trying to access Cloud Functions with Firebase Hosting. That error appears when there is a problem accessing your Function. Just to give you an idea, here's a thread with similar error:
Imporant Note: Before going to the solution, you must know that Firebase Hosting currently supports Cloud Functions that are in us-central1. You can't use any other regions for your function such as asia-east2.
Moving forward, you need to setup rewrite rules in the hosting section to serve the subpath you configured on your Express App:
firebase.json:
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ {
"source": "/time",
"function": "app"
} ]
}
If you do this correctly, you should be able to access your function through this path:
https://<project-name>.web.app/time
Note that the path in Firebase Hosting is /time, not /app/time.
Reference: https://firebase.google.com/docs/hosting/functions#use_a_web_framework
Upvotes: 4