Search code examples
flaskgoogle-cloud-platformflask-restful

Hit a flask RESTful API from reactive app deployed on GCP


I'm trying to deploy a reactive application on a Google Cloud VM instance for which public IP cannot be enabled. The reactive app hits flask RESTful API endpoints based on user inputs.

Apps and parameters:

  • Flask app (host = '0.0.0.0', port = 5000)
  • Reactive app (host = '0.0.0.0', port = 3000)

Problem: I tried hosting the flask app on the same VM instance, but the reactive app is unable to hit the API endpoints.

Working (local only): The (local) API endpoint is hit when the reactive app and flask app are run locally.

Not working:

  1. I tried deploying the apps on GCP and port-forwarding the reactive (http://localhost:3000) and flask app (http://localhost:5000), but the flask app was not hit
  2. I ran the reactive app locally (on laptop) and port-forwarded the flask app. Surprisingly the local reactive app is able to hit the API endpoint on GCP. But the objective is to have the GCP app hitting the RESTful API
  3. I tried different values for the host ('localhost', '127.0.0.1') and repeated 1, 2

Flask debugger did not record an API call. Unfortunately Chrome's network log does not track requests sent from the reactive app to RESTful API. Therefore, I'm unable to obtain more information on the request from the reactive app.

Is there a way to hit the RESTful API from the reactive app when both are deployed on a GCP VM instance? I can move the flask app to another VM instance, but public IP cannot be enabled and firewall rules cannot be modified.

Note: Not a duplicate of this question because public IP cannot be enabled.


Solution

  • @GagandeepT's answer will provide preliminary diagnostics to check if the host and port are correctly specified. I finally figured out the underlying issue - proxies were redirecting all the http and https traffic away even though the API call is technically 'local'.