pick up BASE_URL from env

This commit is contained in:
Sam Rijs 2018-01-29 09:36:56 +11:00
parent a8aef1bde6
commit 6b26b0b489
3 changed files with 10 additions and 2 deletions

View file

@ -8,6 +8,7 @@ base64 = "0.9.0"
futures = "0.1.18" futures = "0.1.18"
hyper = "0.11.15" hyper = "0.11.15"
hyper-tls = "0.1.2" hyper-tls = "0.1.2"
lazy_static = "1.0.0"
maud = "0.17.2" maud = "0.17.2"
route-recognizer = "0.1.12" route-recognizer = "0.1.12"
semver = { version = "0.9.0", features = ["serde"] } semver = { version = "0.9.0", features = ["serde"] }

View file

@ -7,6 +7,7 @@ extern crate base64;
extern crate futures; extern crate futures;
extern crate hyper; extern crate hyper;
extern crate hyper_tls; extern crate hyper_tls;
#[macro_use] extern crate lazy_static;
extern crate maud; extern crate maud;
extern crate route_recognizer; extern crate route_recognizer;
extern crate semver; extern crate semver;

View file

@ -1,4 +1,5 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::env;
use base64::display::Base64Display; use base64::display::Base64Display;
use hyper::Response; use hyper::Response;
@ -10,7 +11,12 @@ use ::models::crates::{CrateName, AnalyzedDependency};
use ::models::repo::RepoPath; use ::models::repo::RepoPath;
use ::server::assets; 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<CrateName, AnalyzedDependency>) -> Markup { fn dependency_table(title: &str, deps: BTreeMap<CrateName, AnalyzedDependency>) -> Markup {
let count_total = deps.len(); let count_total = deps.len();
@ -65,7 +71,7 @@ fn dependency_table(title: &str, deps: BTreeMap<CrateName, AnalyzedDependency>)
pub fn status_html(analysis_outcome: AnalyzeDependenciesOutcome, repo_path: RepoPath) -> Response { 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 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 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() { let (hero_class, status_asset) = if analysis_outcome.deps.any_outdated() {