The worker always getting 502 when it sent a request to the localhost on dev mode, why?

Hi All,
I just started to develop an endpoint with the CF worker and try to set up a development environment on my localhost. I run a worker on debugging mode which is let us test the worker on our localhost. At the same time, I run a Firebase function on a different port of my localhost. So, the CF worker is running at localhost:5002 and Firebase Function is running at localhost:5001.
The problem is that when I sent a request from CF worker to Firebase Function, fetch API returning a response with 502 bad gateway error. But if I sent a request to the production endpoint with the domain, fetch API returning a response with 200 code. Firebase Function works correctly on my localhost I tested it with the Postman and different ways. I am sure of the correctness of the URL and my usage of fetch functions.
Why am I getting the 502 error? I am stuck in that problem!
Thanks in advance.