Просмотр исходного кода

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

sp.wack 1 год назад
Родитель
Сommit
83c096b974

+ 1 - 1
containers/app/Dockerfile

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

+ 0 - 1
frontend/.env.sample

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

+ 3 - 0
frontend/global.d.ts

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

+ 3 - 0
frontend/public/config.json

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

+ 9 - 0
frontend/src/api/open-hands.ts

@@ -60,6 +60,15 @@ class OpenHands {
     return response.json();
     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
    * Retrieve the list of files available in the workspace
    * @param token User token provided by the server
    * @param token User token provided by the server

+ 1 - 1
frontend/src/routes/_oh._index/route.tsx

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

+ 3 - 0
frontend/src/routes/_oh.tsx

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

+ 1 - 1
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')