diff --git a/hatch_build.py b/hatch_build.py index 837c47f01..2bfa8d8ce 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -44,7 +44,16 @@ def initialize(self, version, build_data): ) try: subprocess.check_call([npm_path, "install"], cwd="web-frontend") - subprocess.check_call([npm_path, "run", "build"], cwd="web-frontend") + subprocess.check_call( + [ + npm_path, + "run", + "build", + "--", + f"--base={os.environ.get('TILED_BUILD_PUBLIC_PATH', '/ui/')}", + ], + cwd="web-frontend", + ) if Path(artifact_path).exists(): shutil.rmtree(artifact_path) shutil.copytree("web-frontend/dist", artifact_path) diff --git a/tiled/commandline/_serve.py b/tiled/commandline/_serve.py index 39e9d2372..01ca96782 100644 --- a/tiled/commandline/_serve.py +++ b/tiled/commandline/_serve.py @@ -612,6 +612,10 @@ def serve_config( # This config was already validated when it was parsed. Do not re-validate. logger.info(f"Using configuration from {Path(config_path).absolute()}") + + if root_path := uvicorn_kwargs.get("root_path", ""): + parsed_config["root_path"] = root_path + web_app = build_app_from_config( parsed_config, source_filepath=config_path, scalable=scalable ) diff --git a/tiled/config.py b/tiled/config.py index 22d76dcec..0f568a06e 100644 --- a/tiled/config.py +++ b/tiled/config.py @@ -183,6 +183,8 @@ def construct_build_app_kwargs( root_tree = MapAdapter(root_mapping, access_policy=root_access_policy) root_tree.include_routers.extend(include_routers) server_settings = {} + if root_path := config.get("root_path", ""): + server_settings["root_path"] = root_path server_settings["allow_origins"] = config.get("allow_origins") server_settings["object_cache"] = config.get("object_cache", {}) server_settings["response_bytesize_limit"] = config.get( diff --git a/tiled/server/app.py b/tiled/server/app.py index 0c3ac7a71..8a05854c7 100644 --- a/tiled/server/app.py +++ b/tiled/server/app.py @@ -266,6 +266,8 @@ async def index( # comments. But they are served as JSON because that is easy to deal with # on the client side. ui_settings = yaml.safe_load(Path(TILED_UI_SETTINGS).read_text()) + if root_path := server_settings.get("root_path", ""): + ui_settings["api_url"] = f"{root_path}{ui_settings['api_url']}" @app.get("/tiled-ui-settings") async def tiled_ui_settings(): diff --git a/web-frontend/src/settings.ts b/web-frontend/src/settings.ts index 218ab9a1e..3800061c1 100644 --- a/web-frontend/src/settings.ts +++ b/web-frontend/src/settings.ts @@ -1,5 +1,7 @@ -const tiledUISettingsURL = "/tiled-ui-settings"; -// TODO Enable a different URL to be chosen at build time? +const basename = import.meta.env.BASE_URL; + +const tiledUISettingsURL = basename.split('/').slice(0, -2).join('/') + '/tiled-ui-settings'; +// Alternate idea // const tiledUISettingsURL = import.meta.env.TILED_UI_SETTINGS || "/tiled-ui-settings"; interface Column {