Skip to content
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

[templates/nextjs] Add .env.* support #1741

Merged
merged 7 commits into from
Feb 22, 2024
Merged

Conversation

addy-pathania
Copy link
Contributor

@addy-pathania addy-pathania commented Feb 16, 2024

Description / Motivation

Provide built-in support for environment variables which Nextjs provides OOTB i.e use .env.* files to load environment variables.
Refer to : Nextjs environment variables support for more details.

Testing Details

  • Unit Test Added
  • Manual Test/Other (Please elaborate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@addy-pathania addy-pathania changed the title Add .env.* support [template/nextjs] Add .env.* support Feb 16, 2024
@addy-pathania addy-pathania changed the title [template/nextjs] Add .env.* support [templates/nextjs] Add .env.* support Feb 17, 2024
Copy link
Contributor

@yavorsk yavorsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, see one comment and maybe PR description should be in its section

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@illiakovalenko illiakovalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think we shouldn't use nextjs env package for this purpose, since these scripts are just node.js scripts, and mainly this package is recommended to be used for unit tests.
    Please, take a look at other packages, like dotenv-flow, I think it was mentioned in a task description
  2. If I start the app in production mode or connected, how the "loadEnvConfig" will automatically identify which .env file needs to be loaded? Probably, you need to set up NODE_ENV env variable, from my understanding

@addy-pathania
Copy link
Contributor Author

addy-pathania commented Feb 20, 2024

@illiakovalenko

  1. I think we shouldn't use nextjs env package for this purpose, since these scripts are just node.js scripts, and mainly this package is recommended to be used for unit tests.
    Please, take a look at other packages, like dotenv-flow, I think it was mentioned in a task description
  2. If I start the app in production mode or connected, how the "loadEnvConfig" will automatically identify which .env file needs to be loaded? Probably, you need to set up NODE_ENV env variable, from my understanding
  1. I don't think it's mentioned anywhere that it should only be used for unit test purpose. We can load this for any nodejs environment. Also, we mentioned to look into this solution as well in our grooming notes. From my understanding it's better to use this rather than installing another dependency.
  2. This will be the priority order for loading of env files. Yes they would have to set the NODE_ENV if they want to use the .env.$(NODE_ENV) file but for me it worked without setting NODE_ENV.

@illiakovalenko
Copy link
Contributor

@sc-addypathania
1- it's mentioned here
https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#test-environment-variables
or it's commonly used still?
image
2 - if you start your app:

  • jss:start:connected .env.development should be pulled
  • jss start:production .env.production should be pulled
    is it working?

Co-authored-by: Adam Brauer <[email protected]>
Copy link
Contributor

@ambrauer ambrauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@addy-pathania addy-pathania merged commit dd36bab into dev Feb 22, 2024
1 check passed
@addy-pathania addy-pathania deleted the feature/jss-388-env-support branch February 22, 2024 22:16
@addy-pathania
Copy link
Contributor Author

@sc-addypathania 1- it's mentioned here https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#test-environment-variables or it's commonly used still? image 2 - if you start your app:

  • jss:start:connected .env.development should be pulled
  • jss start:production .env.production should be pulled
    is it working?

@illiakovalenko FYI these comments should be addressed now with the dotenv-flow package and adding NODE_ENV to the package.json scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants