I am trying to migrate to firebase. But before that I gave it a small try by performing the following one. I have successfully added and deployed cloud function but am getting a error
Error: Forbidden
Your client does not have permission to get URL /app/lol from this server.
This is occurring on execution of following code:
const functions = require('firebase-functions');
const express = require('express');
const app = express()
// tried adding this as middleware
// const cors = require('core'({origin: true}))
var admin = require('firebase-admin');
// app.use(cors)
var serviceAccount = require("./ServiceAccount.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<my-app>.firebaseio.com/"
});
app.get('/lol', (req, res) => {
res.send(`${Date.now()}`);
})
exports.site = functions.https.onRequest(app);
my firebase.json is as following:
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"rewrites" :[{
"source" : "**",
"function" : "app"
}],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
when i go to the route, it takes me to the google auth and after signing through correct account. I get the error.
Whats the issue here!
2 alternative ways to solve:
you should change
exports.site = functions.https.onRequest(app);
to
exports.app = functions.https.onRequest(app);
you could modify firebase.json from
"rewrites" :[{
"source" : "**",
"function" : "app"
}],
to
"rewrites" :[{
"source" : "**",
"function" : "site"
}],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With