This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b751983c6dd AIP-38 Allow specifiying injectable server url (#46900)
b751983c6dd is described below

commit b751983c6dd4207d7d6d310e0fe7cca9aa456eca
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Fri Feb 21 17:47:49 2025 +0100

    AIP-38 Allow specifiying injectable server url (#46900)
    
    * AIP-38 Allow specifiying injectable server url
    
    * Add templatable backend url from config
    
    * Fix CI
    
    * Move the base init logic to queryClient so the config loader uses the 
appropriate endpoint
---
 airflow/api_fastapi/core_api/app.py | 7 ++++++-
 airflow/ui/dev/index.html           | 1 +
 airflow/ui/index.html               | 1 +
 airflow/ui/src/queryClient.ts       | 5 +++++
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/airflow/api_fastapi/core_api/app.py 
b/airflow/api_fastapi/core_api/app.py
index 08f37812c3c..7d27f8b9c39 100644
--- a/airflow/api_fastapi/core_api/app.py
+++ b/airflow/api_fastapi/core_api/app.py
@@ -31,6 +31,7 @@ from starlette.staticfiles import StaticFiles
 from starlette.templating import Jinja2Templates
 
 from airflow.api_fastapi.core_api.middleware import FlaskExceptionsMiddleware
+from airflow.configuration import conf
 from airflow.exceptions import AirflowException
 from airflow.settings import AIRFLOW_PATH
 from airflow.www.extensions.init_dagbag import get_dag_bag
@@ -76,7 +77,11 @@ def init_views(app: FastAPI) -> None:
 
     @app.get("/webapp/{rest_of_path:path}", response_class=HTMLResponse, 
include_in_schema=False)
     def webapp(request: Request, rest_of_path: str):
-        return templates.TemplateResponse("/index.html", {"request": request}, 
media_type="text/html")
+        return templates.TemplateResponse(
+            "/index.html",
+            {"request": request, "backend_server_base_url": 
conf.get("fastapi", "base_url")},
+            media_type="text/html",
+        )
 
 
 def init_plugins(app: FastAPI) -> None:
diff --git a/airflow/ui/dev/index.html b/airflow/ui/dev/index.html
index a719206af3f..aab0888e331 100644
--- a/airflow/ui/dev/index.html
+++ b/airflow/ui/dev/index.html
@@ -3,6 +3,7 @@
 <html lang="en" style="height: 100%">
   <head>
     <meta charset="UTF-8" />
+    <meta name="backend-server-base-url" content="{{ backend_server_base_url 
}}" />
     <link rel="icon" type="image/png" 
href="http://localhost:5173/public/pin_32.png"; />
     <script type="module" src="http://localhost:5173/@vite/client";></script>
     <script type="module">
diff --git a/airflow/ui/index.html b/airflow/ui/index.html
index f888d6fcc34..d27bbf2edc9 100644
--- a/airflow/ui/index.html
+++ b/airflow/ui/index.html
@@ -4,6 +4,7 @@
     <meta charset="UTF-8" />
     <link rel="icon" type="image/png" href="/pin_32.png" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <meta name="backend-server-base-url" content="{{ backend_server_base_url 
}}" />
     <title>Airflow 3.0</title>
   </head>
   <body style="height: 100%">
diff --git a/airflow/ui/src/queryClient.ts b/airflow/ui/src/queryClient.ts
index fac657943dc..13452ba3782 100644
--- a/airflow/ui/src/queryClient.ts
+++ b/airflow/ui/src/queryClient.ts
@@ -18,6 +18,11 @@
  */
 import { QueryClient } from "@tanstack/react-query";
 
+import { OpenAPI } from "openapi/requests/core/OpenAPI";
+
+// Dynamically set the base URL for XHR requests based on the meta tag.
+OpenAPI.BASE = 
document.querySelector("meta[name='backend-server-base-url']")?.getAttribute("content")
 ?? "";
+
 export const queryClient = new QueryClient({
   defaultOptions: {
     mutations: {

Reply via email to