Skip to content

Npm build prefix #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2024
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
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