Removed the API route in favour of server side rendering; Updated documentation to list environment variables (#9)
- Use server side rendering in the `getServerEnv` library function, rather than using the API route - Updated `README.md` to list the relevant environment variables for the frontend and backend - Updated `NETWORKING.md` to reflect the changes made in `docker-compose.yaml`
This commit is contained in:
parent
ec158c0cdf
commit
f6ae79b0b5
4 changed files with 41 additions and 50 deletions
17
README.md
17
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:
|
||||
|
|
|
@ -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
|
||||
|
|
16
ui/app/api/env/route.ts
vendored
16
ui/app/api/env/route.ts
vendored
|
@ -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);
|
||||
}
|
|
@ -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<string> {
|
||||
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 ?? "";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue