-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
base: main
Are you sure you want to change the base?
Conversation
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", |
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.
This will cause .env.example to overwrite .env after each installation. I need to think again
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.
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.
web/app/layout.tsx
Outdated
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.
Client components cannot get the env values w/o these relaying code. Zod validations also fail on the client side. Plz give it a full test.
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.
Can you share your testing method and screenshots of test results? There is no problem with my test here.
I have no problem outputting the variables in the NormalForm component.
// web/app/signin/normalForm.tsx
'use client'
import { env } from '@/env'
const NormalForm = () => {
const { t } = useTranslation()
const router = useRouter()
const { locale } = useContext(I18n)
for (const key in env)
console.log(key, env[key])
// ……
}
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.
I have a question here🤔, is there any writing operation required for these variables?
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
dify/web/app/layout.tsx
Lines 43 to 44 in 13cd409
Type of Change
Please delete options that are not relevant.
@t3-oss/env-core
andzod
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:
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint gods