diff --git a/tiled/commandline/_serve.py b/tiled/commandline/_serve.py index 39e9d2372..491f55474 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 rp := uvicorn_kwargs.get('root_path', ''): + parsed_config['root_path'] = rp + 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..fa8361b4c 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..8c72c30d2 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/App.tsx b/web-frontend/src/App.tsx index e92d919dd..df87ef905 100644 --- a/web-frontend/src/App.tsx +++ b/web-frontend/src/App.tsx @@ -39,7 +39,7 @@ function App() { } , []); return ( - + }> diff --git a/web-frontend/src/settings.ts b/web-frontend/src/settings.ts index 218ab9a1e..ddf82afd1 100644 --- a/web-frontend/src/settings.ts +++ b/web-frontend/src/settings.ts @@ -1,4 +1,5 @@ -const tiledUISettingsURL = "/tiled-ui-settings"; +const basename = import.meta.env.BASE_URL; +const tiledUISettingsURL = `/tiled/tiled-ui-settings`; // TODO Enable a different URL to be chosen at build time? // const tiledUISettingsURL = import.meta.env.TILED_UI_SETTINGS || "/tiled-ui-settings";