Skip to content

Commit

Permalink
feat(api/env): add relevant env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
JowiAoun authored and MFarabi619 committed Oct 5, 2024
1 parent 29303eb commit 07a3096
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/env/src/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import process from 'node:process'
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

export const sharedEnv = createEnv({
shared: {
NODE_ENV: z.enum(['development', 'test', 'production']).optional(),
},
runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
},
})
15 changes: 15 additions & 0 deletions libs/env/src/website/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import process from 'node:process'
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

import { sharedEnv } from '../shared'

export const env = createEnv({
extends: [sharedEnv],
server: {
DATABASE_URL: z.string().url().startsWith('postgres'),
},
experimental__runtimeEnv: {},
emptyStringAsUndefined: true,
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
})
24 changes: 24 additions & 0 deletions libs/env/src/website/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import process from 'node:process'
import { createEnv } from '@t3-oss/env-nextjs'
import { z } from 'zod'

import { sharedEnv } from '../shared'
import { env as dbEnv } from './db'

export const env = createEnv({
extends: [sharedEnv, dbEnv],
shared: {
PORT: z.coerce.number().default(3000),
},
server: {
AUTH_SECRET: z.string(),

AUTH_GOOGLE_ID: z.string().optional(),
AUTH_GOOGLE_SECRET: z.string().optional(),
},
experimental__runtimeEnv: {
PORT: process.env.PORT,
},
emptyStringAsUndefined: true,
// skipValidation: !!process.env.['SKIP_ENV_VALIDATION'],
})

0 comments on commit 07a3096

Please sign in to comment.