Home > Back-end >  How to define envs for GAE?
How to define envs for GAE?

Time:11-30

I created web app that consist with two separate parts: server and client. And I want to deploy it to google cloud with app engine.

I already did it, but the main problem is unworking env_variables that I need for correct work of application that I defined in .yaml files.

I don't understand why the env variables doesn't work, If I do it in accordance to docs.

I wrote .yaml file to each part. Here the file structure:
./
--client/
----source_files...
----client.yaml
--server/
----source_files...
----api.yaml
--dispatch.yaml

Here the content of each file.

client.yaml:

runtime: nodejs16
service: default
handlers:
  - url: /(.*\.. )$
    static_files: build/\1
    upload: build/(.*\.. )$
  - url: /.*
    static_files: build/index.html
    upload: build/index.html
env_variables:
  API_LINK: "https://gcloudezample-11111.lm.r.appsport.com"

api.yaml:

runtime: nodejs16
service: api
env: standard
env_variables:
  MONGO_DB_PWD: "db_password"

dispatch.yaml:

dispatch:
  - url: '*/api'
    service: api

Then I deployed this parts in .yaml files order above.

The result is working frontend but failed api requests, because the wrong request URL: http://localhost:3001/v1/my-route

Screenshot

CodePudding user response:

It's a common misunderstanding of how a website works. Take 2 sec and think about it: What are doing your frontend part?

Let me help

handlers:
  - url: /(.*\.. )$
    static_files: build/\1
    upload: build/(.*\.. )$
  - url: /.*
    static_files: build/index.html
    upload: build/index.html

It serves only static files. Therefore, only static file means no processing, no instances, no variable definition in the runtime context because only static files are served.

The runtime is on the client browser that run the JS code.

Note: the counterpart great advantage, that the static page serving is free (in term of resource usage because there is no instance up and running to serve your files; the egress is billed)


So now, how to solve this?

Simply build your static files with the API_LINK value INSIDE the static code.

  • Related