This commit is contained in:
2026-03-22 13:55:23 +08:00
parent c3f196ded4
commit 69099986e0
616 changed files with 38942 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
import { h } from 'vue'
import { toast } from 'vue-sonner'
import { z } from 'zod'
/**
* Load .env file and validate it against the schema
* Has this file, it will be loaded automatically by vite and we will be have environment variables available type
* If EnvSchema Object has Key but not in .env file, it will be have a error in page
*/
const EnvSchema = z.object({
// Add your environment variables here, for example:
// VITE_API_BASE_URL: z.string().url(),
VITE_SERVER_API_URL: z.string(),
VITE_SERVER_API_PREFIX: z.string(),
VITE_SERVER_API_TIMEOUT: z.coerce.number().default(5000),
})
export type env = z.infer<typeof EnvSchema>
// eslint-disable-next-line ts/no-redeclare
const { data: env, error } = EnvSchema.safeParse(import.meta.env)
if (error) {
console.error('❌ Invalid env')
const flattenError = z.flattenError(error)
console.error(flattenError)
setTimeout(() => {
toast.error(`Env error: you should check your .env file`, {
description: h(
'pre',
{ class: 'mt-2 rounded-md bg-slate-950 p-4 text-wrap' },
h('code', { class: 'text-white' }, JSON.stringify(flattenError, null, 2)),
),
duration: 10000,
})
}, 1000)
}
export default env!