-
Notifications
You must be signed in to change notification settings - Fork 279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure app config variables have values at build-time #1296
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The computed
prop and computeConfigValue
required to evaluate the string seems unnecessary. I think you're onto something with the fallback to env values in scjssconfig.ts
...
Could we just make this a first step to populate all of the config defaults?
For example, in generate-config.ts, something like:
const defaultConfig: JssConfig = {
sitecoreApiKey: process.env[`${constantCase('sitecoreApiKey')}`] || 'no-api-key-set',
sitecoreApiHost: process.env[`${constantCase('sitecoreApiHost')}`] || '',
jssAppName: process.env[`${constantCase('jssAppName')}`] || 'Unknown',
graphQLEndpointPath: process.env[`${constantCase('graphQLEndpointPath')}`] || '',
defaultLanguage: process.env[`${constantCase('defaultLanguage')}`] || 'en',
};
Or maybe even better, a default
config plugin that does this? Could probably then lose the defaultConfig altogether in generate-config.ts.
Reworked the approach, moving away from dynamic evaluation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, see a few comments
packages/create-sitecore-jss/src/templates/nextjs-multisite/scripts/config/plugins/multisite.ts
Outdated
Show resolved
Hide resolved
packages/create-sitecore-jss/src/templates/nextjs-multisite/scripts/config/plugins/multisite.ts
Outdated
Show resolved
Hide resolved
packages/create-sitecore-jss/src/templates/nextjs/scripts/config/plugins/fallback.ts
Outdated
Show resolved
Hide resolved
packages/create-sitecore-jss/src/templates/nextjs/scripts/config/plugins/fallback.ts
Show resolved
Hide resolved
packages/create-sitecore-jss/src/templates/nextjs/scripts/generate-config.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Resolves #1291 |
This PR slightly reworks how a config in nextjs app is built.
Each value is resolved with the following logic:
This roughly follows pre-plugin approach to building config where env values take precedence, other sources follow as fallback.
This also ensures that graphQL endpoint will have a correct value, if hostname values is present in either env or scjssconfig.
Types of changes