Skip to content

Commit

Permalink
MNT: Thread root_path through more places
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Feb 2, 2024
1 parent c083ef4 commit ebb6dbf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tiled/commandline/_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions tiled/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions tiled/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion web-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function App() {
} , []);
return (
<SettingsContext.Provider value={settings}>
<BrowserRouter basename={basename}>
<BrowserRouter basename={basename}>
<ErrorBoundary>
<Suspense fallback={<Skeleton variant="rectangular" />}>
<Routes>
Expand Down
3 changes: 2 additions & 1 deletion web-frontend/src/settings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down

0 comments on commit ebb6dbf

Please sign in to comment.