From 6b26b0b4892db89fd37630b8a36cc93b7f245630 Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Mon, 29 Jan 2018 09:36:56 +1100 Subject: [PATCH] pick up BASE_URL from env --- Cargo.toml | 1 + src/main.rs | 1 + src/server/views/status_html.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8808596..24f1a0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ base64 = "0.9.0" futures = "0.1.18" hyper = "0.11.15" hyper-tls = "0.1.2" +lazy_static = "1.0.0" maud = "0.17.2" route-recognizer = "0.1.12" semver = { version = "0.9.0", features = ["serde"] } diff --git a/src/main.rs b/src/main.rs index 6771302..156fadf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ extern crate base64; extern crate futures; extern crate hyper; extern crate hyper_tls; +#[macro_use] extern crate lazy_static; extern crate maud; extern crate route_recognizer; extern crate semver; diff --git a/src/server/views/status_html.rs b/src/server/views/status_html.rs index 6f5fed0..460e3e8 100644 --- a/src/server/views/status_html.rs +++ b/src/server/views/status_html.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::env; use base64::display::Base64Display; use hyper::Response; @@ -10,7 +11,12 @@ use ::models::crates::{CrateName, AnalyzedDependency}; use ::models::repo::RepoPath; use ::server::assets; -const SELF_BASE_URL: &'static str = "https://shiny-robots.herokuapp.com"; +lazy_static! { + static ref SELF_BASE_URL: String = { + env::var("BASE_URL") + .unwrap_or_else(|_| "http://localhost:8080".to_string()) + }; +} fn dependency_table(title: &str, deps: BTreeMap) -> Markup { let count_total = deps.len(); @@ -65,7 +71,7 @@ fn dependency_table(title: &str, deps: BTreeMap) pub fn status_html(analysis_outcome: AnalyzeDependenciesOutcome, repo_path: RepoPath) -> Response { let self_path = format!("repo/{}/{}/{}", repo_path.site.as_ref(), repo_path.qual.as_ref(), repo_path.name.as_ref()); - let status_base_url = format!("{}/{}", SELF_BASE_URL, self_path); + let status_base_url = format!("{}/{}", &SELF_BASE_URL as &str, self_path); let title = format!("{} / {} - Dependency Status", repo_path.qual.as_ref(), repo_path.name.as_ref()); let (hero_class, status_asset) = if analysis_outcome.deps.any_outdated() {