[ALL-551] chore(frontend): Retrieve APP_MODE from the server (#4423)

This commit is contained in:
sp.wack
2024-10-17 18:35:21 +04:00
committed by GitHub
parent 015df47e53
commit 83c096b974
8 changed files with 21 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ RUN npm install -g npm@10.5.1
RUN npm ci
COPY ./frontend ./
RUN npm run make-i18n && npm run build
RUN npm run build
FROM python:3.12.3-slim AS backend-builder

View File

@@ -3,4 +3,3 @@ VITE_MOCK_API="false" # true or false
# GitHub OAuth
VITE_GITHUB_CLIENT_ID=""
VITE_APP_MODE="oss" # "oss" or "saas"

3
frontend/global.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
interface Window {
__APP_MODE__?: "saas" | "oss";
}

View File

@@ -0,0 +1,3 @@
{
"APP_MODE": "oss"
}

View File

@@ -60,6 +60,15 @@ class OpenHands {
return response.json();
}
static async getConfig(): Promise<{ APP_MODE: "saas" | "oss" }> {
const response = await fetch(`${OpenHands.BASE_URL}/config.json`, {
headers: {
"Cache-Control": "no-cache",
},
});
return response.json();
}
/**
* Retrieve the list of files available in the workspace
* @param token User token provided by the server

View File

@@ -113,7 +113,7 @@ function Home() {
const { files } = useSelector((state: RootState) => state.initalQuery);
const handleConnectToGitHub = () => {
const isSaas = import.meta.env.VITE_APP_MODE === "saas";
const isSaas = window.__APP_MODE__ === "saas";
if (isSaas) {
window.location.href = githubAuthUrl;

View File

@@ -26,6 +26,9 @@ import NewProjectIcon from "#/assets/new-project.svg?react";
import DocsIcon from "#/assets/docs.svg?react";
export const clientLoader = async () => {
const config = await OpenHands.getConfig();
window.__APP_MODE__ = config.APP_MODE;
let token = localStorage.getItem("token");
const ghToken = localStorage.getItem("ghToken");

View File

@@ -798,4 +798,4 @@ def github_callback(auth_code: AuthCode):
)
app.mount('/', StaticFiles(directory='./frontend/build', html=True), name='dist')
app.mount('/', StaticFiles(directory='./frontend/build/client', html=True), name='dist')