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 optional configuration for content path #182

Closed

Conversation

karthik2804
Copy link
Contributor

No description provided.

Copy link
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

I'm not really qualified to review this so mostly signing off that it's not sabotage grin. I left a couple of suggestions but they're not blocking.

@@ -28,13 +28,14 @@ pub fn render(req: Request) -> Result<Response> {
_ => false,
};

let optinal_path_prefix = spin_sdk::config::get("optional_path_prefix").unwrap_or_default();
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Suggested change
let optinal_path_prefix = spin_sdk::config::get("optional_path_prefix").unwrap_or_default();
let optional_path_prefix = spin_sdk::config::get("optional_path_prefix").unwrap_or_default();

Although I'm not sure optional is helpful here. You're going to use the (Rust) variable regardless of what it contains. Just call it path_prefix.

I'd recommend doing the same for the Spin config/variable. When I read a manifest I'll either see a path_prefix or I won't.

Copy link
Contributor

Choose a reason for hiding this comment

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

So my actual suggestion is

Suggested change
let optinal_path_prefix = spin_sdk::config::get("optional_path_prefix").unwrap_or_default();
let path_prefix = spin_sdk::config::get("path_prefix").unwrap_or_default();

// Get the request path.
let path_info = match req.headers().get("spin-path-info") {
Some(p) => {
if p == "/" {
DEFAULT_INDEX.to_owned()
format!("{}{}", optinal_path_prefix, DEFAULT_INDEX.to_owned())
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider pulling out the common prefixing operation e.g.

let path = if p == "/" { DEFAULT_INDEX.to_owned() }  else { p.to_str()?.to_owned() };  // same as existing code
format!("{path_prefix}{path}")

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.

2 participants