0

I have a web application that has frontend (React) and backend(Express) separately, so in my local environment, frontend is running on localhost:8080 while backend is running on localhost:3000.

I could deploy backend server to App Engine running on https://[app_name].appspot.com.

and then I also deployed frontend to Google Cloud Storage by referencing this. However, the frontend application is also running on https://[app_name].appspot.com.
When I open the app, it is showing frontend but api call is not working.

I do not have custom domain yet, and I am also using postgresql. Is there any way to set different url for frontend and backend? or Am I doing something wrong in the structure to set an application?

kay
  • 1,369
  • 4
  • 15
  • 27

1 Answers1

1

Mapping to a domain name (either the default appspot.com one or a custom one) is done at the application level, not at the service level. Your both services, being part of the same app, would thus be mapped to the same domain.

Side note here: I assume you chose different service/module names for your services (in the respective .yaml files), otherwise they overwrite each-other at deployment time.

Routing a request to one service or another is done based on pattern matching on the filepath portion in the URL, not on the host/domain portion. First match wins and no match always goes to the default service.

Because of this typically the frontent is the default service (you can also leave it unnamed). An any other, more dedicated service, have an identifying pattern in their URL path which is used for routing with a dispatch.yaml file. In your case, for example, the backend service would be the specialized one and could serve, let's say, URLs starting with /backend/, thus could have a dispatch.file like this:

dispatch:
  - url: "*/backend/*"
    module: <backend-service-name>

More or less related:

Note: You have to account for the specific pattern inside the specialized services as well. If, for example, your backend service currently serves a request for /index.html you'll have to adjust it to serve /backend/index.html instead.

It might be possible to make both services work side by side without a dispatch file, using other routing methods (see the entire How Requests are Routed section), but IMHO it's more difficult to set up and more fragile. Especially when trying to also use custom domains.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97