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 { BookOpenText, ClockIcon, Delete, ScanEye } from 'lucide-react';
import Link from 'next/link'; import Link from 'next/link';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
export interface Chat { export interface Chat {
id: string; id: string;
@ -22,7 +22,7 @@ const Page = () => {
const fetchChats = async () => { const fetchChats = async () => {
setLoading(true); setLoading(true);
const res = await fetch(`${process.env.BACKEND_API_URL}/chats`, { const res = await fetch(`${getServerEnv("BACKEND_API_URL")}/chats`, {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -10,7 +10,7 @@ import { toast } from 'sonner';
import { useSearchParams } from 'next/navigation'; import { useSearchParams } from 'next/navigation';
import { getSuggestions } from '@/lib/actions'; import { getSuggestions } from '@/lib/actions';
import Error from 'next/error'; import Error from 'next/error';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
export type Message = { export type Message = {
messageId: string; messageId: string;
@ -40,7 +40,7 @@ const useSocket = (
); );
const providers = await fetch( const providers = await fetch(
`${process.env.BACKEND_API_URL}/models`, `${getServerEnv("BACKEND_API_URL")}/models`,
{ {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -221,7 +221,7 @@ const loadMessages = async (
setNotFound: (notFound: boolean) => void, setNotFound: (notFound: boolean) => void,
) => { ) => {
const res = await fetch( const res = await fetch(
`${process.env.BACKEND_API_URL}/chats/${chatId}`, `${getServerEnv("BACKEND_API_URL")}/chats/${chatId}`,
{ {
method: 'GET', method: 'GET',
headers: { headers: {

View file

@ -3,7 +3,7 @@ import { Dialog, Transition } from '@headlessui/react';
import { Fragment, useState } from 'react'; import { Fragment, useState } from 'react';
import { toast } from 'sonner'; import { toast } from 'sonner';
import { Chat } from '@/app/library/page'; import { Chat } from '@/app/library/page';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
const DeleteChat = ({ const DeleteChat = ({
chatId, chatId,
@ -21,7 +21,7 @@ const DeleteChat = ({
setLoading(true); setLoading(true);
try { try {
const res = await fetch( const res = await fetch(
`${process.env.BACKEND_API_URL}/chats/${chatId}`, `${getServerEnv("BACKEND_API_URL")}/chats/${chatId}`,
{ {
method: 'DELETE', method: 'DELETE',
headers: { headers: {

View file

@ -4,7 +4,7 @@ import { useState } from 'react';
import Lightbox from 'yet-another-react-lightbox'; import Lightbox from 'yet-another-react-lightbox';
import 'yet-another-react-lightbox/styles.css'; import 'yet-another-react-lightbox/styles.css';
import { Message } from './ChatWindow'; import { Message } from './ChatWindow';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
type Image = { type Image = {
url: string; url: string;
@ -35,7 +35,7 @@ const SearchImages = ({
const chatModel = localStorage.getItem('chatModel'); const chatModel = localStorage.getItem('chatModel');
const res = await fetch( const res = await fetch(
`${process.env.BACKEND_API_URL}/images`, `${getServerEnv("BACKEND_API_URL")}/images`,
{ {
method: 'POST', method: 'POST',
headers: { headers: {

View file

@ -4,7 +4,7 @@ import { useState } from 'react';
import Lightbox, { GenericSlide, VideoSlide } from 'yet-another-react-lightbox'; import Lightbox, { GenericSlide, VideoSlide } from 'yet-another-react-lightbox';
import 'yet-another-react-lightbox/styles.css'; import 'yet-another-react-lightbox/styles.css';
import { Message } from './ChatWindow'; import { Message } from './ChatWindow';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
type Video = { type Video = {
url: string; url: string;
@ -48,7 +48,7 @@ const Searchvideos = ({
const chatModel = localStorage.getItem('chatModel'); const chatModel = localStorage.getItem('chatModel');
const res = await fetch( const res = await fetch(
`${process.env.BACKEND_API_URL}/videos`, `${getServerEnv("BACKEND_API_URL")}/videos`,
{ {
method: 'POST', method: 'POST',
headers: { headers: {

View file

@ -8,7 +8,7 @@ import React, {
type SelectHTMLAttributes, type SelectHTMLAttributes,
} from 'react'; } from 'react';
import ThemeSwitcher from './theme/Switcher'; import ThemeSwitcher from './theme/Switcher';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {} interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
@ -89,7 +89,7 @@ const SettingsDialog = ({
if (isOpen) { if (isOpen) {
const fetchConfig = async () => { const fetchConfig = async () => {
setIsLoading(true); setIsLoading(true);
const res = await fetch(`${process.env.BACKEND_API_URL}/config`, { const res = await fetch(`${getServerEnv("BACKEND_API_URL")}/config`, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
@ -149,7 +149,7 @@ const SettingsDialog = ({
setIsUpdating(true); setIsUpdating(true);
try { try {
await fetch(`${process.env.BACKEND_API_URL}/config`, { await fetch(`${getServerEnv("BACKEND_API_URL")}/config`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',

View file

@ -1,11 +1,11 @@
import { Message } from '@/components/ChatWindow'; import { Message } from '@/components/ChatWindow';
import process from 'process'; import { getServerEnv } from '@/lib/serverEnvironment';
export const getSuggestions = async (chatHisory: Message[]) => { export const getSuggestions = async (chatHisory: Message[]) => {
const chatModel = localStorage.getItem('chatModel'); const chatModel = localStorage.getItem('chatModel');
const chatModelProvider = localStorage.getItem('chatModelProvider'); 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', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',