I have a written a very basic API which will return the services. I tried to run this API in emulator but it return the empty data
{
"status": "success",
"statusCode": 200,
"message": "Services retrieved",
"data": []
}
I have setup the firestore, functions and database emulators. And I am using
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0"
Any idea why the data response is empty ?
EDIT
This is my method to call the service
export const activeServices = functions.https.onRequest((request, response) => {
let services = new Array<string>();
admin.firestore().collection(newServices).get()
.then(serviceSnapshot => {
serviceSnapshot.docs.forEach(doc => {
if(doc.data().service_active){
services.push(doc.data().service_name)
}
})
const successResponse = common.success("success", 200, "Services retrieved", services)
response.send(successResponse)
})
.catch(error => {
const errorResponse = common.error("fail", 500, "Failed to get active services")
console.error(errorResponse)
response.send(errorResponse)
})
})
I tried to execute this and it return nothing and executed the same functions after deploying. And I got the response. From below answers I think running only functions will try to communicate with production database.
firebase emulators:start --only functions
functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
⚠ External network resource requested!
- URL: "http://xxx.xxx.xxx.xxx/computeMetadata/v1/instance"
- Be careful, this may be a production service.
⚠ External network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
- Be careful, this may be a production service.
This looks like it's trying to communicate to production but couldn't make any successful request.