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

Commit bf402c6

Browse files
authored
Merge pull request #5 from netlify/set-site-env-locally
Set site environment variables in local dev
2 parents 8f6c6d4 + 568d5db commit bf402c6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/commands/dev/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,21 @@ 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
}
142+
process.env.NETLIFY_DEV = 'true'
132143
let settings = serverSettings()
133144
if (!(settings && settings.cmd)) {
134145
this.log('No dev server detected, using simple static server')

0 commit comments

Comments
 (0)