Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 33ccce2

Browse files
committed
Set site environment variables in local dev
We'll want more control over this in the future, especially in terms of distinguishing between dev context and production context. For now this is a starting point. With this change any locally defined environment variable will also take precendence over any env var set in the site settings or from an addon
1 parent e5f8e82 commit 33ccce2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/commands/dev/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,19 @@ class DevCommand extends Command {
125125
addon.slug
126126
}`
127127
for (const key in addon.env) {
128-
process.env[key] = addon.env[key]
128+
process.env[key] = process.env[key] || addon.env[key]
129129
}
130130
})
131+
const api = this.netlify.api
132+
const apiSite = await api.getSite({site_id: site.id})
133+
// TODO: We should move the environment outside of build settings and possibly have a
134+
// `/api/v1/sites/:site_id/environment` endpoint for it that we can also gate access to
135+
// In the future and that we could make context dependend
136+
if (apiSite.build_settings && apiSite.build_settings.env) {
137+
for (const key in apiSite.build_settings.env) {
138+
process.env[key] = process.env[key] || apiSite.build_settings.env[key]
139+
}
140+
}
131141
}
132142
let settings = serverSettings()
133143
if (!(settings && settings.cmd)) {

0 commit comments

Comments
 (0)