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

Inject Cargo Version into html #24

Merged
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dbif = { path = 'dbif'}
lnd-rs = { path = "lnd-rs" }
voca_rs = "1.14.0"
configure_me = "0.4.0"
handlebars = "4.2.1"

[build-dependencies]
configure_me_codegen = "0.4.1"
9 changes: 6 additions & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use std::error::Error;
use std::fmt;
use std::fs;
use voca_rs::*;
use handlebars::Handlebars;
use serde_json::json;



//Constants --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -33,12 +36,12 @@ pub async fn home(ctx: Context) -> Response {
url::form_urlencoded::parse(v.as_bytes()).into_owned().collect()
}).unwrap_or_else(HashMap::new);

//println!("** Params: {:#?}", _params);

let reg = Handlebars::new();
let doc = fs::read_to_string("webroot/html/home.html").expect("Something went wrong reading the file.");
let doc_rendered = reg.render_template(&doc, &json!({"version": ctx.state.version})).expect("Something went wrong rendering the file");
return hyper::Response::builder()
.status(StatusCode::OK)
.body(format!("{}", doc).into())
.body(format!("{}", doc_rendered).into())
.unwrap();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const LND_STANDARD_TLSCERT_LOCATION: &str = "/lnd/tls.cert";
pub struct AppState {
pub state_thing: String,
pub remote_ip: String,
pub version: String,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -277,6 +278,7 @@ async fn main() {
let app_state = AppState {
state_thing: some_state.clone(),
remote_ip: conn.remote_addr().to_string().clone(),
version: version.to_string(),
};

let database_file_path = db_filepath.clone();
Expand Down
2 changes: 1 addition & 1 deletion webroot/html/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h5 class="titleHeader">Helipad: Boost Tracker</h5>
<div class="msg_history"></div>
</div>
</div>
<div class="versionFooter"><a href="https://github.com/Podcastindex-org/helipad">v0.1.7</a></div>
<div class="versionFooter"><a href="https://github.com/Podcastindex-org/helipad">v{{version}}</a></div>
</div>
</div>
</body>
Expand Down