Skip to content

Commit

Permalink
Npm build prefix (#646)
Browse files Browse the repository at this point in the history
* BLD: make the base path in the web frontend build configurable

* MNT: Thread root_path through more places

* MNT: string munge root path in settings

* STY: appease linter

* Nitpicks

---------

Co-authored-by: Dan Allan <dallan@bnl.gov>
  • Loading branch information
tacaswell and danielballan authored Feb 2, 2024
1 parent c76d1b3 commit 4248258
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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 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
)
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
6 changes: 4 additions & 2 deletions web-frontend/src/settings.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 4248258

Please sign in to comment.