diff --git a/src/lib/serverEnvironment.ts b/src/lib/serverEnvironment.ts new file mode 100644 index 0000000..93a3ec3 --- /dev/null +++ b/src/lib/serverEnvironment.ts @@ -0,0 +1,5 @@ +import process from 'process'; + +export async function getServerEnv(envVar: string) { + return process.env[envVar]; +} \ No newline at end of file diff --git a/ui/app/library/page.tsx b/ui/app/library/page.tsx index d91b04a..a4925ab 100644 --- a/ui/app/library/page.tsx +++ b/ui/app/library/page.tsx @@ -5,7 +5,7 @@ import { formatTimeDifference } from '@/lib/utils'; import { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react'; import Link from 'next/link'; import { useEffect, useState } from 'react'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; export interface Chat { id: string; @@ -22,7 +22,7 @@ const Page = () => { const fetchChats = async () => { setLoading(true); - const res = await fetch(`${process.env.BACKEND_API_URL}/chats`, { + const res = await fetch(`${getServerEnv("BACKEND_API_URL")}/chats`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index f423013..0aa7a25 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -10,7 +10,7 @@ import { toast } from 'sonner'; import { useSearchParams } from 'next/navigation'; import { getSuggestions } from '@/lib/actions'; import Error from 'next/error'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; export type Message = { messageId: string; @@ -40,7 +40,7 @@ const useSocket = ( ); const providers = await fetch( - `${process.env.BACKEND_API_URL}/models`, + `${getServerEnv("BACKEND_API_URL")}/models`, { headers: { 'Content-Type': 'application/json', @@ -221,7 +221,7 @@ const loadMessages = async ( setNotFound: (notFound: boolean) => void, ) => { const res = await fetch( - `${process.env.BACKEND_API_URL}/chats/${chatId}`, + `${getServerEnv("BACKEND_API_URL")}/chats/${chatId}`, { method: 'GET', headers: { diff --git a/ui/components/DeleteChat.tsx b/ui/components/DeleteChat.tsx index 48ec006..3a18758 100644 --- a/ui/components/DeleteChat.tsx +++ b/ui/components/DeleteChat.tsx @@ -3,7 +3,7 @@ import { Dialog, Transition } from '@headlessui/react'; import { Fragment, useState } from 'react'; import { toast } from 'sonner'; import { Chat } from '@/app/library/page'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; const DeleteChat = ({ chatId, @@ -21,7 +21,7 @@ const DeleteChat = ({ setLoading(true); try { const res = await fetch( - `${process.env.BACKEND_API_URL}/chats/${chatId}`, + `${getServerEnv("BACKEND_API_URL")}/chats/${chatId}`, { method: 'DELETE', headers: { diff --git a/ui/components/SearchImages.tsx b/ui/components/SearchImages.tsx index 4578876..be9dba7 100644 --- a/ui/components/SearchImages.tsx +++ b/ui/components/SearchImages.tsx @@ -4,7 +4,7 @@ import { useState } from 'react'; import Lightbox from 'yet-another-react-lightbox'; import 'yet-another-react-lightbox/styles.css'; import { Message } from './ChatWindow'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; type Image = { url: string; @@ -35,7 +35,7 @@ const SearchImages = ({ const chatModel = localStorage.getItem('chatModel'); const res = await fetch( - `${process.env.BACKEND_API_URL}/images`, + `${getServerEnv("BACKEND_API_URL")}/images`, { method: 'POST', headers: { diff --git a/ui/components/SearchVideos.tsx b/ui/components/SearchVideos.tsx index 8fafd29..097a57b 100644 --- a/ui/components/SearchVideos.tsx +++ b/ui/components/SearchVideos.tsx @@ -4,7 +4,7 @@ import { useState } from 'react'; import Lightbox, { GenericSlide, VideoSlide } from 'yet-another-react-lightbox'; import 'yet-another-react-lightbox/styles.css'; import { Message } from './ChatWindow'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; type Video = { url: string; @@ -48,7 +48,7 @@ const Searchvideos = ({ const chatModel = localStorage.getItem('chatModel'); const res = await fetch( - `${process.env.BACKEND_API_URL}/videos`, + `${getServerEnv("BACKEND_API_URL")}/videos`, { method: 'POST', headers: { diff --git a/ui/components/SettingsDialog.tsx b/ui/components/SettingsDialog.tsx index 54cf280..458bb56 100644 --- a/ui/components/SettingsDialog.tsx +++ b/ui/components/SettingsDialog.tsx @@ -8,7 +8,7 @@ import React, { type SelectHTMLAttributes, } from 'react'; import ThemeSwitcher from './theme/Switcher'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; interface InputProps extends React.InputHTMLAttributes {} @@ -89,7 +89,7 @@ const SettingsDialog = ({ if (isOpen) { const fetchConfig = async () => { setIsLoading(true); - const res = await fetch(`${process.env.BACKEND_API_URL}/config`, { + const res = await fetch(`${getServerEnv("BACKEND_API_URL")}/config`, { headers: { 'Content-Type': 'application/json', }, @@ -149,7 +149,7 @@ const SettingsDialog = ({ setIsUpdating(true); try { - await fetch(`${process.env.BACKEND_API_URL}/config`, { + await fetch(`${getServerEnv("BACKEND_API_URL")}/config`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/ui/lib/actions.ts b/ui/lib/actions.ts index 6b18603..afe6b8a 100644 --- a/ui/lib/actions.ts +++ b/ui/lib/actions.ts @@ -1,11 +1,11 @@ import { Message } from '@/components/ChatWindow'; -import process from 'process'; +import { getServerEnv } from '@/lib/serverEnvironment'; export const getSuggestions = async (chatHisory: Message[]) => { const chatModel = localStorage.getItem('chatModel'); const chatModelProvider = localStorage.getItem('chatModelProvider'); - const res = await fetch(`${process.env.BACKEND_API_URL}/suggestions`, { + const res = await fetch(`${getServerEnv("BACKEND_API_URL")}/suggestions`, { method: 'POST', headers: { 'Content-Type': 'application/json',