问题
I'm using react on google app engine.
As is written in the documentation: https://cloud.google.com/appengine/docs/standard/nodejs/runtime#environment_variables
I can access the following Env Variable:
Environment variable Description
GAE_APPLICATION The ID of your App Engine application.
GAE_DEPLOYMENT_ID The ID of the current deployment.
GAE_ENV The App Engine environment. Set to standard.
GAE_INSTANCE The ID of the instance on which your service is currently running.
GAE_MEMORY_MB The amount of memory available to the application process, in MB.
GAE_RUNTIME The runtime specified in your app.yaml file.
GAE_SERVICE The service name specified in your app.yaml file. If no service name is specified, it is set to default.
GAE_VERSION The current version label of your service.
GOOGLE_CLOUD_PROJECT The GCP project ID associated with your application.
NODE_ENV Set to production when your service is deployed.
PORT The port that receives HTTP requests.
When I deploy my app on google app engine and print process.env console.log(process.env) I have only:
NODE_ENV: "production"
PUBLIC_URL: ""
In the documentation is explicitly written "The following environment variables are set by the runtime", but there are no one of them.
What is wrong?
回答1:
What it means by "The following environment variables are set by the runtime" is applicable to applications executed by node
. As such, the process.env
printed when ran from an express.js application contains those environment variables because you would be executing your code as node .bin/www
or node server.js
as opposed to react-scripts start
when deploying a react.js application. In this case, it is create-react-app who has the responsibility in setting the environment variables. Alternatively, you can manually set these environment variables in accordance to the create-react-app
specifications.
来源:https://stackoverflow.com/questions/57729098/how-to-access-process-env-on-google-app-engine-with-nodejs