π OpenHands: AI-Driven Development
[ALL-551] chore(frontend): Retrieve `APP_MODE` from the server (#4423)
sp.wack83c096b974ee
diff --git a/containers/app/Dockerfile b/containers/app/Dockerfileindex ce2c0ba75c..507f45659b 100644--- a/containers/app/Dockerfile+++ b/containers/app/Dockerfile@@ -8,7 +8,7 @@ RUN npm install -g [email protected]RUN npm ciCOPY ./frontend ./-RUN npm run make-i18n && npm run build+RUN npm run buildFROM python:3.12.3-slim AS backend-builderdiff --git a/frontend/.env.sample b/frontend/.env.sampleindex ba82f3b80b..9d6bf87a70 100644--- a/frontend/.env.sample+++ b/frontend/.env.sample@@ -3,4 +3,3 @@ VITE_MOCK_API="false" # true or false# GitHub OAuthVITE_GITHUB_CLIENT_ID=""-VITE_APP_MODE="oss" # "oss" or "saas"diff --git a/frontend/global.d.ts b/frontend/global.d.tsnew file mode 100644index 0000000000..e71757d809--- /dev/null+++ b/frontend/global.d.ts@@ -0,0 +1,3 @@+interface Window {+ __APP_MODE__?: "saas" | "oss";+}diff --git a/frontend/public/config.json b/frontend/public/config.jsonnew file mode 100644index 0000000000..bdc29014a4--- /dev/null+++ b/frontend/public/config.json@@ -0,0 +1,3 @@+{+ "APP_MODE": "oss"+}diff --git a/frontend/src/api/open-hands.ts b/frontend/src/api/open-hands.tsindex a0d3087de5..be41cf7967 100644--- a/frontend/src/api/open-hands.ts+++ b/frontend/src/api/open-hands.ts@@ -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 serverdiff --git a/frontend/src/routes/_oh._index/route.tsx b/frontend/src/routes/_oh._index/route.tsxindex 6cf98852e4..21b6bc1979 100644--- a/frontend/src/routes/_oh._index/route.tsx+++ b/frontend/src/routes/_oh._index/route.tsx@@ -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;diff --git a/frontend/src/routes/_oh.tsx b/frontend/src/routes/_oh.tsxindex fc9793c453..0449443dbd 100644--- a/frontend/src/routes/_oh.tsx+++ b/frontend/src/routes/_oh.tsx@@ -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");diff --git a/openhands/server/listen.py b/openhands/server/listen.pyindex 32c93a117e..2f47282367 100644--- a/openhands/server/listen.py+++ b/openhands/server/listen.py@@ -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')