-
Notifications
You must be signed in to change notification settings - Fork 50
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
Conversation
Signed-off-by: karthik2804 <[email protected]>
a644287
to
9391729
Compare
There was a problem hiding this 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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
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.
There was a problem hiding this comment.
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
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()) |
There was a problem hiding this comment.
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}")
No description provided.