Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
import './src/env.js'
Comment thread
robotzurg marked this conversation as resolved.

import { createMDX } from 'fumadocs-mdx/next'
import createNextIntlPlugin from 'next-intl/plugin'
import './src/env.js'

const withMDX = createMDX()

Expand Down
3 changes: 2 additions & 1 deletion src/app/api/neatqueue-webhook/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import crypto from 'node:crypto'
import { type NextRequest, NextResponse } from 'next/server'
import { env } from '@/env'
import { globalEmitter } from '@/lib/events'
import type { PlayerState } from '@/server/api/routers/player-state'
import { PLAYER_STATE_KEY, redis } from '@/server/redis'
import { leaderboardService } from '@/server/services/leaderboard'

const EXPECTED_QUERY_SECRET = process.env.WEBHOOK_QUERY_SECRET
const EXPECTED_QUERY_SECRET = env.WEBHOOK_QUERY_SECRET

type WebhookPlayer = {
id?: string | number
Expand Down
4 changes: 2 additions & 2 deletions src/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Nemesis } from '@/app/_components/nemesis'
import { Spectral } from '@/app/_components/spectral'
import { Xmult } from '@/app/_components/xmult'
import { Button } from '@/components/ui/button'
import { env } from '@/env'
import { CDN_URL } from '@/shared/constants'
import { metadataImage } from '../../../../lib/metadata'
import { source } from '../../../../lib/source'
Expand Down Expand Up @@ -73,8 +74,7 @@ export default async function Page(props: {
...defaultMdxComponents,
img: (props: ImageZoomProps) => {
const isDev =
process.env.NODE_ENV === 'development' ||
process.env.IS_PREVIEW === 'true'
env.NODE_ENV === 'development' || env.IS_PREVIEW === 'true'
if (isDev) {
return <ImageZoom {...props} />
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as AvatarPrimitive from '@radix-ui/react-avatar'
import type * as React from 'react'

import { env } from '@/env'
import { cn } from '@/lib/utils'
import { CDN_URL } from '@/shared/constants'

Expand All @@ -27,7 +28,7 @@ function AvatarImage({
src,
...props
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
const isDev = process.env.NODE_ENV === 'development'
const isDev = env.NODE_ENV === 'development'
let finalSrc = src
if (typeof src === 'string' && src.startsWith('/') && !isDev) {
finalSrc = `${CDN_URL}${src}`
Expand Down
14 changes: 14 additions & 0 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export const env = createEnv({
MINIO_BUCKET_NAME: z.string(),
MINIO_LEADERBOARD_BUCKET_NAME: z.string(),
MINIO_USE_SSL: z.enum(['true', 'false']).default('false'),
API_TOKEN: z.string(),
VERCEL_URL: z.string().optional(),
PORT: z.string().optional(),
IS_PREVIEW: z.string().optional(),
},

/**
* Shared variables available on both client and server (e.g. NODE_ENV).
*/
shared: {
NODE_ENV: z
.enum(['development', 'test', 'production'])
.default('development'),
Expand Down Expand Up @@ -59,6 +69,10 @@ export const env = createEnv({
MINIO_LEADERBOARD_BUCKET_NAME: process.env.MINIO_LEADERBOARD_BUCKET_NAME,
MINIO_USE_SSL: process.env.MINIO_USE_SSL,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
API_TOKEN: process.env.API_TOKEN,
VERCEL_URL: process.env.VERCEL_URL,
PORT: process.env.PORT,
IS_PREVIEW: process.env.IS_PREVIEW,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
Expand Down
3 changes: 2 additions & 1 deletion src/server/api/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { initTRPC, TRPCError } from '@trpc/server'
import superjson from 'superjson'
import { ZodError } from 'zod'

import { env } from '@/env'
import { auth } from '@/server/auth'
import { db } from '@/server/db'

Expand Down Expand Up @@ -58,7 +59,7 @@ const t = initTRPC.context<typeof createTRPCContext>().create({
}

// Clear stack trace in production to prevent retention
if (process.env.NODE_ENV === 'production') {
if (env.NODE_ENV === 'production') {
const { stack: _stack, ...safeFormatted } =
formatted as typeof formatted & {
stack?: unknown
Expand Down
5 changes: 3 additions & 2 deletions src/server/services/botlatro.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { eq } from 'drizzle-orm'
import { env } from '@/env'
import { db } from '../db'
import { transcripts } from '../db/schema'
import { redis } from '../redis'
Expand All @@ -13,7 +14,7 @@ export const botlatro_service = {
get_active_matches: async (): Promise<ActiveMatchQueue[]> => {
const response = await fetch(`${BOTLATRO_URL}api/matches/active-counts`, {
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
Authorization: `Bearer ${env.API_TOKEN}`,
},
})
if (!response.ok) {
Expand Down Expand Up @@ -112,7 +113,7 @@ export const botlatro_service = {
`${BOTLATRO_URL}api/transcripts/view/${gameNumber}`,
{
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
Authorization: `Bearer ${env.API_TOKEN}`,
},
}
)
Expand Down
9 changes: 5 additions & 4 deletions src/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server'
import { useState } from 'react'
import SuperJSON from 'superjson'

import { env } from '@/env'
import type { AppRouter } from '@/server/api/root'
import { createQueryClient } from './query-client'

Expand Down Expand Up @@ -51,7 +52,7 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === 'development' ||
env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),

Expand Down Expand Up @@ -87,9 +88,9 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
}

function getBaseUrl() {
if (process.env.NODE_ENV === 'production') return 'https://balatromp.com'
if (env.NODE_ENV === 'production') return 'https://balatromp.com'
if (typeof window !== 'undefined') return window.location.origin
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`
if (env.VERCEL_URL) return `https://${env.VERCEL_URL}`

return `http://localhost:${process.env.PORT ?? 3000}`
return `http://localhost:${env.PORT ?? 3000}`
}
3 changes: 2 additions & 1 deletion test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { desc, eq } from 'drizzle-orm'
import { createClient } from 'redis'
import { env } from '@/env'
import { db } from '@/server/db'
import { player_games } from '@/server/db/schema'

const redisClient = await createClient({ url: process.env.REDIS_URL })
const redisClient = await createClient({ url: env.REDIS_URL })
.on('error', (err) => console.error('Redis Client Error', err))
.connect()

Expand Down