Attempt trigger process call server side

This commit is contained in:
Andrew Pennington 2024-08-15 22:37:24 +01:00
parent 73bf7f3d79
commit a62e39a776
No known key found for this signature in database
GPG key ID: E9DA097213FD17EA
8 changed files with 21 additions and 16 deletions

View file

@ -0,0 +1,5 @@
import process from 'process';
export async function getServerEnv(envVar: string) {
return process.env[envVar];
}

View file

@ -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',

View file

@ -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: {

View file

@ -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: {

View file

@ -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: {

View file

@ -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: {

View file

@ -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<HTMLInputElement> {}
@ -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',

View file

@ -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',