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

feat: verify environment variables #4115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TinsFox
Copy link
Contributor

@TinsFox TinsFox commented May 6, 2024

Description

Use @t3-oss/env-core zod to verify environment variables. When the environment variables fail to be read, an error will be reported when starting the project, ensuring the integrity of the necessary parameters required when the project is started.

At the same time, the environment variables exposed on the body have been removed and exposed through the recommended method of nextjs.

dify/web/app/layout.tsx

Lines 39 to 44 in 13cd409

data-api-prefix={process.env.NEXT_PUBLIC_API_PREFIX}
data-pubic-api-prefix={process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX}
data-public-edition={process.env.NEXT_PUBLIC_EDITION}
data-public-sentry-dsn={process.env.NEXT_PUBLIC_SENTRY_DSN}
data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE}
data-public-site-about={process.env.NEXT_PUBLIC_SITE_ABOUT}

⚠️ I may need someone to help me check what these two environment variables do.

dify/web/app/layout.tsx

Lines 43 to 44 in 13cd409

data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE}
data-public-site-about={process.env.NEXT_PUBLIC_SITE_ABOUT}

Type of Change

Please delete options that are not relevant.

  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement
  • Dependency upgrade, two new dependencies have been added, @t3-oss/env-core and zod

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

There are no destructive updates. Although environment variables need to be checked, a default .env file is generated during installation. This modification can be said to only add a type hint to the environment variable.

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. dependencies Pull requests that update a dependency file ☕️ typescript Pull request that update TypeScript code. labels May 6, 2024
@zxhlyh zxhlyh requested a review from nite-knite May 7, 2024 02:31
@takatost takatost requested a review from zxhlyh May 7, 2024 06:39
web/package.json Outdated
@@ -9,7 +9,7 @@
"lint": "next lint",
"fix": "next lint --fix",
"eslint-fix": "eslint --fix",
"prepare": "cd ../ && node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install ./web/.husky",
"prepare": "cp .env.example .env && cd ../ && node -e \"if (process.env.NODE_ENV !== 'production'){process.exit(1)} \" || husky install ./web/.husky",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will cause .env.example to overwrite .env after each installation. I need to think again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use a script to solve the problem. When .evn already has the same key value as .env.example, skip the update to avoid being overwritten.

ea3f54f (#4115)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file size:L This PR changes 100-499 lines, ignoring generated files. ☕️ typescript Pull request that update TypeScript code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant