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
|
|
@ -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
Add a link
Reference in a new issue