chore: Don't require envs in build time, and load them dynamically#11
Merged
patrick11514 merged 1 commit intomainfrom Jan 29, 2026
Merged
chore: Don't require envs in build time, and load them dynamically#11patrick11514 merged 1 commit intomainfrom
patrick11514 merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors environment variable management by moving from SvelteKit's static environment imports ($env/static/private) to dynamic imports ($env/dynamic/private) with centralized validation using Zod. This change allows environment variables to be loaded at runtime rather than at build time, making the application more flexible for different deployment environments.
Changes:
- Created a new centralized
env.tsmodule with Zod schema validation for all environment variables - Migrated all files using
$env/static/privateto import from the newenvmodule - Removed
parseIntcalls where Zod'sz.coerce.number()now handles string-to-number conversion
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/lib/server/env.ts |
New file that defines and validates environment variables using Zod schema, providing type-safe access to configuration |
src/lib/server/variables.ts |
Updated to use the new centralized env module instead of static env imports |
src/lib/server/nina.ts |
Removed default fallback logic as defaults are now handled by Zod schema |
src/lib/server/functions.ts |
Updated to import FILE_FOLDER from the new env module |
src/routes/image/[name]/+server.ts |
Updated to import FILE_FOLDER from the new env module and reorganized imports |
src/lib/server/_routes/upload.ts |
Updated to import FILE_FOLDER from the new env module and reorganized imports |
src/lib/server/_routes/login.ts |
Updated to import COOKIE_EXPIRE from the new env module |
src/lib/server/_routes/article.ts |
Updated to import FILE_FOLDER from the new env module |
src/lib/server/_routes/ai.ts |
Updated to import GEMINI_API_KEY from the new env module |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.