Skip to content
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

Add --base-path CLI option to override the URL path in the tilejson #1205

Merged
merged 21 commits into from
Feb 27, 2024

Conversation

sharkAndshark
Copy link
Collaborator

@sharkAndshark sharkAndshark commented Feb 20, 2024

Try to fix #1185

  • Add --base-path to CLI
  • Add base_path to config file
  • Add tests
  • Update doc

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx for working on this!

martin/src/args/srv.rs Outdated Show resolved Hide resolved
martin/src/config.rs Outdated Show resolved Hide resolved
martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
martin/src/srv/tiles_info.rs Show resolved Hide resolved
martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
martin/src/utils/utilities.rs Outdated Show resolved Hide resolved
@sharkAndshark
Copy link
Collaborator Author

I will refactor these functions/tests later.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
docs/src/run-with-cli.md Outdated Show resolved Hide resolved
martin/src/args/srv.rs Outdated Show resolved Hide resolved
martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
martin/src/utils/utilities.rs Outdated Show resolved Hide resolved
@sharkAndshark sharkAndshark marked this pull request as ready for review February 25, 2024 14:39
martin/src/utils/utilities.rs Outdated Show resolved Hide resolved
martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, seems like you can't easily get rid of an extra string alloc here. Oh well.

Comment on lines 40 to 47
if let Ok(uri) = path.parse::<Uri>() {
let mut result = uri.path();
while result.len() > 1 {
result = result.trim_end_matches('/');
}
return Ok(result.to_string());
}
Err(BasePathError(path.to_string()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be an infinite loop?

You don't need a loop - just do this:

Suggested change
if let Ok(uri) = path.parse::<Uri>() {
let mut result = uri.path();
while result.len() > 1 {
result = result.trim_end_matches('/');
}
return Ok(result.to_string());
}
Err(BasePathError(path.to_string()))
if let Ok(uri) = path.parse::<Uri>() {
Ok(uri.path().trim_end_matches('/').to_string())
} else {
Err(BasePathError(path.to_string()))
}

Copy link
Collaborator Author

@sharkAndshark sharkAndshark Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems for "//" trim_end_matches would return empty string "".. That would fail our test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if you leave it, it will break format!("{base_path}/{}", path.source_ids) -- because it would create two slashes

martin/src/srv/tiles_info.rs Outdated Show resolved Hide resolved
}
if let Ok(uri) = path.parse::<Uri>() {
let mut result = uri.path().to_string();
while result.chars().last().is_some_and(|v| v == '/') && result.len() > 1 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pop() back as the trim_end_matches would return "' for "//", any better way to use the trim methods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, lets keep it simple - use this method just for the user-supplied base_path parsing - in which case it should be empty if the user only passed /. And keep the original code for x-rewrite-url header.

I will look at it later, see if it can be optimized, but its not worth it now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually It's not bad to use pop() here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But your suggestion is more simple

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!!!

@nyurik nyurik enabled auto-merge (squash) February 27, 2024 16:00
@nyurik nyurik merged commit 99cd99e into maplibre:main Feb 27, 2024
16 of 17 checks passed
@sharkAndshark sharkAndshark deleted the basepath branch February 28, 2024 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add --base-path CLI option to override the URL path in the tilejson
2 participants