Set environment variable for build in Netlify

后端 未结 6 1103
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 05:52

I\'m trying to set an environment variable for an API key that I don\'t want in my code. My source javascript looks something like this :

.get(`http://api-ur         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-03 06:31

    You can use the Netlify's config file also ... You can find documentation here. Also i wanted to have the same ENV variables with with different values per branch/environment. This workaround worked for me:

    Create a netlify.toml file like:

    [build]
      NUXT_ENV_BASE_API = "/api"
      NUXT_ENV_HOST_DOMAIN = "https://your-domain.gr"
    
    [context.branch-deploy]
      environment = { NUXT_ENV_BASE_API = "/dev-api", NUXT_ENV_HOST_DOMAIN = "https://dev.your-domain.gr" }
    
    [context.production]
      environment = { NUXT_ENV_BASE_API = "/api", NUXT_ENV_HOST_DOMAIN = "https://your-domain.gr" }
    

    And deploy in Netlify ...

提交回复
热议问题