diff --git a/README.md b/README.md index 3c87acc..d87a90e 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,23 @@ There are mainly 2 ways of installing Perplexica - With Docker, Without Docker. See the [installation documentation](https://github.com/ItzCrazyKns/Perplexica/tree/master/docs/installation) for more information like exposing it your network, etc. +### Environment Variables + +You can use environment variables to override the settings provided in your `config.toml` file. + +##### Frontend Environment Variables +- `BACKEND_API_URL` +- `BACKEND_WS_URL` + +##### Backend Environment Variables +- `PORT` +- `SIMILARITY_MEASURE` +- `OPENAI_API_KEY` +- `GROQ_API_KEY` +- `ANTHROPIC_API_KEY` +- `SEARXNG_API_ENDPOINT` +- `OLLAMA_API_ENDPOINT` + ### Ollama Connection Errors If you're encountering an Ollama connection error, it is likely due to the backend being unable to connect to Ollama's API. To fix this issue you can: diff --git a/docs/installation/NETWORKING.md b/docs/installation/NETWORKING.md index baad296..53c526e 100644 --- a/docs/installation/NETWORKING.md +++ b/docs/installation/NETWORKING.md @@ -19,9 +19,9 @@ docker compose down --rmi all 5. Replace `127.0.0.1` with the IP address of the server Perplexica is running on in these two lines: ``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 +environment: + - 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 @@ -57,9 +57,9 @@ nano docker-compose.yaml 5. Replace `127.0.0.1` with the server IP in these lines: ``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 +environment: + - 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 @@ -95,9 +95,9 @@ nano docker-compose.yaml 5. Replace `127.0.0.1` with the server IP: ``` -args: - - NEXT_PUBLIC_API_URL=http://127.0.0.1:3001/api - - NEXT_PUBLIC_WS_URL=ws://127.0.0.1:3001 +environment: + - 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/app/api/env/route.ts b/ui/app/api/env/route.ts deleted file mode 100644 index 01cf6fb..0000000 --- a/ui/app/api/env/route.ts +++ /dev/null @@ -1,16 +0,0 @@ -import process from 'process'; -import { NextResponse } from 'next/server'; - -// Enable the Runtime -export const runtime = "edge" - -export async function GET(_request: Request) { - // Access environment variables - const envVars = { - 'BACKEND_API_URL': process.env.BACKEND_API_URL ?? process.env.NEXT_PUBLIC_API_URL, - 'BACKEND_WS_URL': process.env.BACKEND_WS_URL ?? process.env.NEXT_PUBLIC_WS_URL - } - - // Return the environment variables as a JSON response - return NextResponse.json(envVars); -} diff --git a/ui/lib/serverEnvironment.ts b/ui/lib/serverEnvironment.ts index 1179fd6..a9444b7 100644 --- a/ui/lib/serverEnvironment.ts +++ b/ui/lib/serverEnvironment.ts @@ -1,29 +1,19 @@ -async function fetchConfig() { - try { - const response = await fetch('/api/env'); - if (response.ok) { - const data = await response.json(); - sessionStorage.setItem('cachedConfig', JSON.stringify(data)); - return data; - } else { - throw new Error('Failed to fetch config'); - } - } catch (error) { - return null; - } -} +'use server'; + +import process from 'process'; export async function getServerEnv(envVar: string): Promise { - const cachedConfig = JSON.parse(sessionStorage.getItem('cachedConfig') || 'null'); - - if (cachedConfig) { - return cachedConfig[envVar]; + let result: string | undefined; + switch (envVar) { + case "BACKEND_API_URL": + result = process.env.BACKEND_API_URL ?? process.env.NEXT_PUBLIC_API_URL; + break; + case "BACKEND_WS_URL": + result = process.env.BACKEND_WS_URL ?? process.env.NEXT_PUBLIC_WS_URL; + break; + default: + result = process.env[envVar]; + break; } - - const data = await fetchConfig(); - if (!data) { - return ""; - } - - return data[envVar]; + return result ?? ""; }