我在谷歌应用引擎上使用反应。
如文档中所写:https://cloud.google.com/appengine/docs/standard/nodejs/runtime#environment_variables
我可以访问以下环境变量:
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.
当我在谷歌应用引擎上部署我的应用程序并打印process.env console.log(process.env(时,我只有:
NODE_ENV: "production"
PUBLIC_URL: ""
在文档中明确写了"以下环境变量由运行时设置",但没有一个。
怎么了?
"以下环境变量由运行时设置"的含义适用于node
执行的应用程序。因此,从 express.js 应用程序运行时打印的process.env
包含这些环境变量,因为您将以node .bin/www
或node server.js
的方式执行代码,而不是在部署 react.js 应用程序时react-scripts start
。在这种情况下,负责设置环境变量的是创建-反应-应用程序。或者,您可以根据create-react-app
规范手动设置这些环境变量。