Helpers for config and API client #1452
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm trying to add Storybook stories for the
FileNode
component but this isn't possible because it imports Redux actions which rely on readingwindow.process.env
, which throws an error in the storybook environment. 😢I noticed that the code for reading the env var is duplicated throughout the app, so I've refactored into a helper called
getClient(key)
. This also abstracts where the var is being read from, so in future we can read it from elsewhere, or try a few different places (local storage, then the env) without changing the calling code.The biggest user of the env var is the
API_URL
in the redux actions. I've createdapiClient
which is an instance ofaxios
that provides a single place to configure theAPI_URL
and basic config that we want to apply to all communication to the editor API.I have verified that this pull request:
npm run lint
)Fixes #123