-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make env vars a bit easier to understand/follow in adapter-node (#4360)
* make env vars a bit easier to understand/follow in adapter-node * tidy up types * fail noisily if opts.env is provided * changeset * update docs * lint * rename env in README * custom prefix instead of names themselves * tweak changeset * typo * oops * lint * error if env var namespace is already occupied * Update packages/adapter-node/tsconfig.json Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com> Co-authored-by: mrkishi <mauriciokishi@gmail.com> Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com>
- Loading branch information
1 parent
7cb5ee9
commit 37520a3
Showing
9 changed files
with
78 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/adapter-node': patch | ||
--- | ||
|
||
[breaking] Replace `options.env` with `options.envPrefix` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* global ENV_PREFIX */ | ||
|
||
const expected = new Set([ | ||
'SOCKET_PATH', | ||
'HOST', | ||
'PORT', | ||
'ORIGIN', | ||
'XFF_DEPTH', | ||
'ADDRESS_HEADER', | ||
'PROTOCOL_HEADER', | ||
'HOST_HEADER' | ||
]); | ||
|
||
if (ENV_PREFIX) { | ||
for (const name in process.env) { | ||
if (name.startsWith(ENV_PREFIX)) { | ||
const unprefixed = name.slice(ENV_PREFIX.length); | ||
if (!expected.has(unprefixed)) { | ||
throw new Error( | ||
`You should change envPrefix (${ENV_PREFIX}) to avoid conflicts with existing environment variables — unexpectedly saw ${name}` | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
* @param {any} fallback | ||
*/ | ||
export function env(name, fallback) { | ||
const prefixed = ENV_PREFIX + name; | ||
return prefixed in process.env ? process.env[prefixed] : fallback; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.