update env variables to use zod

pull/3/head
TZGyn 2 years ago
parent ea5806d376
commit d3db0e9463
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,9 +1,7 @@
import { drizzle } from 'drizzle-orm/postgres-js' import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres' import postgres from 'postgres'
import * as schema from './schema' import * as schema from './schema'
import { env } from '$lib/env'
const client = postgres( const client = postgres(env.DATABASE_URL)
process.env.DATABASE_URL ??
'postgres://postgres:password@127.0.0.1:5432/link-shortener',
)
export const db = drizzle(client, { schema }) export const db = drizzle(client, { schema })

@ -1,8 +1,9 @@
import { env } from '$lib/env'
import { drizzle } from 'drizzle-orm/postgres-js' import { drizzle } from 'drizzle-orm/postgres-js'
import { migrate } from 'drizzle-orm/postgres-js/migrator' import { migrate } from 'drizzle-orm/postgres-js/migrator'
import postgres from 'postgres' import postgres from 'postgres'
const sql = postgres(Bun.env.DATABASE_URL ?? '', { max: 1 }) const sql = postgres(env.DATABASE_URL, { max: 1 })
const db = drizzle(sql) const db = drizzle(sql)
await migrate(db, { migrationsFolder: 'drizzle' }) await migrate(db, { migrationsFolder: 'drizzle' })

@ -0,0 +1,8 @@
import { z } from 'zod'
const envSchema = z.object({
DATABASE_URL: z.string().url(),
PUBLIC_SHORTENER_URL: z.string(),
})
export const env = envSchema.parse(process.env)

@ -4,8 +4,9 @@ import { eq } from 'drizzle-orm'
import type { RequestHandler } from './$types' import type { RequestHandler } from './$types'
import QRCode from 'qrcode' import QRCode from 'qrcode'
import { redirect } from '@sveltejs/kit' import { redirect } from '@sveltejs/kit'
import { env } from '$lib/env'
const shortenerUrl = Bun.env.PUBLIC_SHORTENER_URL ?? 'shortener.url' const shortenerUrl = env.PUBLIC_SHORTENER_URL
export const GET: RequestHandler = async (event) => { export const GET: RequestHandler = async (event) => {
const shortenerId = event.params.id const shortenerId = event.params.id

Loading…
Cancel
Save