Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@ def get_bundle_url(plugin_prefix: str, bundle_filename: str) -> str:
"""
Return the bundle URL for a plugin's React bundle.

Uses an absolute URL when api.base_url is a full URL so the bundle loads
correctly in Vite dev mode, where import() resolves relative to the script
origin (5173) rather than the document origin (28080).
Only the path is used, never the origin in api.base_url: the host UI resolves it against the
page it was loaded from, so the bundle still loads when the browser reaches Airflow through
a different origin than base_url names, such as a local proxy.
"""
path = get_base_url_path(f"{plugin_prefix}/static/{bundle_filename}")
base_url = conf.get("api", "base_url", fallback="/")
if base_url.startswith(("http://", "https://")):
parsed = urlparse(base_url)
return f"{parsed.scheme}://{parsed.netloc}" + path
return path
return get_base_url_path(f"{plugin_prefix}/static/{bundle_filename}")
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# under the License.
from __future__ import annotations

import pytest

from airflow.providers.common.ai.plugins._plugin_urls import get_base_url_path, get_bundle_url

from tests_common.test_utils.config import conf_vars
Expand All @@ -36,11 +38,15 @@ def test_default_base_url_returns_a_relative_path(self):
with conf_vars({("api", "base_url"): "/"}):
assert get_bundle_url("/ai-model", "model.umd.cjs") == "/ai-model/static/model.umd.cjs"

def test_http_base_url_returns_an_absolute_url(self):
"""An absolute bundle_url is needed in Vite dev mode, where import() resolves
relative to the script origin (5173), not the document origin (28080)."""
with conf_vars({("api", "base_url"): "http://example.com/airflow/"}):
assert (
get_bundle_url("/ai-model", "model.umd.cjs")
== "http://example.com/airflow/ai-model/static/model.umd.cjs"
)
@pytest.mark.parametrize(
("base_url", "expected"),
[
("http://localhost:8080", "/ai-model/static/model.umd.cjs"),
("http://example.com/airflow/", "/airflow/ai-model/static/model.umd.cjs"),
],
)
def test_http_base_url_keeps_only_the_path(self, base_url, expected):
"""The browser may reach Airflow on another origin than base_url names (a local proxy),
so the bundle URL must not carry base_url's scheme and host."""
with conf_vars({("api", "base_url"): base_url}):
assert get_bundle_url("/ai-model", "model.umd.cjs") == expected
Loading