[英]How do I read a docker environment variable within a js script?
I have a react app hosted on a node docker container. 我在节点docker容器上托管了一个React应用程序。 I run it and pass it an environment variable
我运行它并将其传递给环境变量
docker run -t -e "ADMIN_HOST_ENV=http://myapp.app:443/api" -p 3000:3000 "myapp"
How can I get that "ADMIN_HOST_ENV" environment variable within the app? 如何在应用程序中获取该“ ADMIN_HOST_ENV”环境变量?
If this is just about the node backend, there's already a question with a answer: Read environment variables in Node.js 如果这仅与节点后端有关,那么已经有一个问题和答案: 在Node.js中读取环境变量
On the frontend, you'll have several options to get at it, create an endpoint to get it, write it to a .js file that's referenced by the frontend, pass it up as a cookie, keep it backend side and only reference it when you hit the backend, etc. 在前端,您将有多种选择来实现它,创建一个端点来获取它,将其写入前端引用的.js文件,将其作为cookie传递,保留在后端,仅引用它当您点击后端时,等等。
I check environment variables when I run my server, write them to an environment.js, and then reference that environment.js in my index.html. 我在运行服务器时检查环境变量,将其写入environment.js,然后在index.html中引用该environment.js。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.