Skip to content

Commit

Permalink
Merge pull request #183 from karthik2804/config/prepend_route_info
Browse files Browse the repository at this point in the history
allow optionally prepending route info
  • Loading branch information
karthik2804 committed Oct 31, 2023
2 parents 0aa0ed2 + f97ec05 commit 2c2be0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/bartholomew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn render(req: Request) -> Result<Response> {
};

// Get the request path.
let path_info = match req.headers().get("spin-path-info") {
let mut path_info = match req.headers().get("spin-path-info") {
Some(p) => {
if p == "/" {
DEFAULT_INDEX.to_owned()
Expand All @@ -50,6 +50,16 @@ pub fn render(req: Request) -> Result<Response> {
config.base_url = Some(url);
}
eprintln!("Base URL: {:?}", &config.base_url);
eprintln!("Prepend route info : {:?}", &config.prepend_route_info);

if config.prepend_route_info {
let route_info = match req.headers().get("spin-component-route") {
Some(route) => route.to_str().unwrap_or_default(),
None => "",
};
path_info = format!("{route_info}{path_info}");
eprintln!("Updated request path: {:?}", path_info);
}

// If a theme is specifed, create theme path
let theme_dir = if config.theme.is_some() {
Expand Down
2 changes: 2 additions & 0 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct SiteInfo {
pub theme: Option<String>,
pub index_site_pages: Option<Vec<String>>,
pub dynamic_templates: Option<Vec<DynamicTemplateConfig>>,
#[serde(default)]
pub prepend_route_info: bool,
pub extra: BTreeMap<String, String>,
}

Expand Down

0 comments on commit 2c2be0d

Please sign in to comment.