drn1008 2019-07-24 13:33
浏览 158
已采纳

如何在AWS EC2中为React&Go设置环境变量

I've made React & Go product in local. And I'm going to deploy it to AWS EC2.

To work in AWS EC2, I need to set environment variables for some secret information.

I've already set env variables for local environment. But I'm not sure about env variables working for production environment(AWS EC2).

I already set env. file for local environment. But not sure how to set environment variables in ec2.

I use environment variables for axios, firebase and mysql.

//axios
   const client = axios.create({
      baseURL: process.env.REACT_APP_API_URL,
    });
    client
      .get('/api/articles')
      .then(response => {
        this.setState({articles: response.data});
      })
      .catch(response => console.log('ERROR!! occurred in Backend.'));
//firebases
const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: '',
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID,
};

firebase.initializeApp(firebaseConfig);

export default firebase;
//mysql
    err := godotenv.Load()
    if err != nil {
        //TODO production

    }
    db, err := sql.Open("mysql", os.Getenv("MYSQL_USER")+":"+os.Getenv("MYSQL_PASSWORD")+"@tcp(localhost:3306)/article")
    if err != nil {
        panic(err.Error())
    }

    defer db.Close()

    err = db.Ping()
    if err != nil {
        panic(err.Error())
    }

Here is the github. https://github.com/jpskgc/article

I'm going to deploy this React & Golang product in AWS EC2. But I'm not sure how to set environment variables.

  • 写回答

2条回答 默认 最新

  • dortmundbvb0624 2019-08-21 08:17
    关注

    I use elastic beanstalk and set environment variables there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 nrf52810-c三个a 程序
  • ¥15 lego-loam跑出来的roll误差很大
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对