From 376220b26ed1a1d150a80b82de310411f568951f Mon Sep 17 00:00:00 2001 From: Andrew Pennington Date: Thu, 15 Aug 2024 20:06:40 +0100 Subject: [PATCH] Rename NEXT_PUBLIC_... env variables to allow reading from env at runtime --- app.dockerfile | 8 ++++---- docs/installation/NETWORKING.md | 12 ++++++------ ui/.env.example | 4 ++-- ui/app/library/page.tsx | 2 +- ui/components/ChatWindow.tsx | 6 +++--- ui/components/DeleteChat.tsx | 2 +- ui/components/SearchImages.tsx | 2 +- ui/components/SearchVideos.tsx | 2 +- ui/components/SettingsDialog.tsx | 4 ++-- ui/lib/actions.ts | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app.dockerfile b/app.dockerfile index c3d3594..aaf9bf2 100644 --- a/app.dockerfile +++ b/app.dockerfile @@ -1,9 +1,9 @@ FROM node:alpine -ARG NEXT_PUBLIC_WS_URL='ws://127.0.0.1:3001' -ARG NEXT_PUBLIC_API_URL='http://127.0.0.1:3001/api' -ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL} -ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} +ARG BACKEND_WS_URL='ws://127.0.0.1:3001' +ARG BACKEND_API_URL='http://127.0.0.1:3001/api' +ENV BACKEND_WS_URL=${BACKEND_WS_URL} +ENV BACKEND_API_URL=${BACKEND_API_URL} WORKDIR /home/perplexica diff --git a/docs/installation/NETWORKING.md b/docs/installation/NETWORKING.md index baad296..c6cd97e 100644 --- a/docs/installation/NETWORKING.md +++ b/docs/installation/NETWORKING.md @@ -20,8 +20,8 @@ docker compose down --rmi all ``` args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + - BACKEND_API_URL=http://127.0.0.1:3001/api + - BACKEND_WS_URL=ws://127.0.0.1:3001 ``` 6. Save and close the `docker-compose.yaml` file @@ -58,8 +58,8 @@ nano docker-compose.yaml ``` args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + - BACKEND_API_URL=http://127.0.0.1:3001/api + - BACKEND_WS_URL=ws://127.0.0.1:3001 ``` 6. Save and exit the editor @@ -96,8 +96,8 @@ nano docker-compose.yaml ``` args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 + - BACKEND_API_URL=http://127.0.0.1:3001/api + - BACKEND_WS_URL=ws://127.0.0.1:3001 ``` 6. Save and exit the editor diff --git a/ui/.env.example b/ui/.env.example index 57a3ed9..78988fd 100644 --- a/ui/.env.example +++ b/ui/.env.example @@ -1,2 +1,2 @@ -NEXT_PUBLIC_WS_URL=ws://localhost:3001 -NEXT_PUBLIC_API_URL=http://localhost:3001/api \ No newline at end of file +BACKEND_WS_URL=ws://localhost:3001 +BACKEND_API_URL=http://localhost:3001/api \ No newline at end of file diff --git a/ui/app/library/page.tsx b/ui/app/library/page.tsx index c7a8bd1..d91b04a 100644 --- a/ui/app/library/page.tsx +++ b/ui/app/library/page.tsx @@ -22,7 +22,7 @@ const Page = () => { const fetchChats = async () => { setLoading(true); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chats`, { + const res = await fetch(`${process.env.BACKEND_API_URL}/chats`, { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index 7d23a09..f423013 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -40,7 +40,7 @@ const useSocket = ( ); const providers = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/models`, + `${process.env.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.NEXT_PUBLIC_API_URL}/chats/${chatId}`, + `${process.env.BACKEND_API_URL}/chats/${chatId}`, { method: 'GET', headers: { @@ -272,7 +272,7 @@ const ChatWindow = ({ id }: { id?: string }) => { const [isWSReady, setIsWSReady] = useState(false); const ws = useSocket( - process.env.NEXT_PUBLIC_WS_URL!, + process.env.BACKEND_WS_URL!, setIsWSReady, setHasError, ); diff --git a/ui/components/DeleteChat.tsx b/ui/components/DeleteChat.tsx index 6deb90f..48ec006 100644 --- a/ui/components/DeleteChat.tsx +++ b/ui/components/DeleteChat.tsx @@ -21,7 +21,7 @@ const DeleteChat = ({ setLoading(true); try { const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/chats/${chatId}`, + `${process.env.BACKEND_API_URL}/chats/${chatId}`, { method: 'DELETE', headers: { diff --git a/ui/components/SearchImages.tsx b/ui/components/SearchImages.tsx index 25c49a3..4578876 100644 --- a/ui/components/SearchImages.tsx +++ b/ui/components/SearchImages.tsx @@ -35,7 +35,7 @@ const SearchImages = ({ const chatModel = localStorage.getItem('chatModel'); const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/images`, + `${process.env.BACKEND_API_URL}/images`, { method: 'POST', headers: { diff --git a/ui/components/SearchVideos.tsx b/ui/components/SearchVideos.tsx index a57902d..8fafd29 100644 --- a/ui/components/SearchVideos.tsx +++ b/ui/components/SearchVideos.tsx @@ -48,7 +48,7 @@ const Searchvideos = ({ const chatModel = localStorage.getItem('chatModel'); const res = await fetch( - `${process.env.NEXT_PUBLIC_API_URL}/videos`, + `${process.env.BACKEND_API_URL}/videos`, { method: 'POST', headers: { diff --git a/ui/components/SettingsDialog.tsx b/ui/components/SettingsDialog.tsx index 55dec50..54cf280 100644 --- a/ui/components/SettingsDialog.tsx +++ b/ui/components/SettingsDialog.tsx @@ -89,7 +89,7 @@ const SettingsDialog = ({ if (isOpen) { const fetchConfig = async () => { setIsLoading(true); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/config`, { + const res = await fetch(`${process.env.BACKEND_API_URL}/config`, { headers: { 'Content-Type': 'application/json', }, @@ -149,7 +149,7 @@ const SettingsDialog = ({ setIsUpdating(true); try { - await fetch(`${process.env.NEXT_PUBLIC_API_URL}/config`, { + await fetch(`${process.env.BACKEND_API_URL}/config`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/ui/lib/actions.ts b/ui/lib/actions.ts index 9cebc95..6b18603 100644 --- a/ui/lib/actions.ts +++ b/ui/lib/actions.ts @@ -5,7 +5,7 @@ export const getSuggestions = async (chatHisory: Message[]) => { const chatModel = localStorage.getItem('chatModel'); const chatModelProvider = localStorage.getItem('chatModelProvider'); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, { + const res = await fetch(`${process.env.BACKEND_API_URL}/suggestions`, { method: 'POST', headers: { 'Content-Type': 'application/json',