Merge branch 'feature/hostname'

This commit is contained in:
Valentin Brandl 2019-04-23 22:54:19 +02:00
commit be42090658
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
2 changed files with 12 additions and 9 deletions

View File

@ -39,9 +39,10 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
lazy_static! { lazy_static! {
static ref CLIENT: reqwest::Client = reqwest::Client::new(); static ref CLIENT: reqwest::Client = reqwest::Client::new();
static ref OPT: Opt = Opt::from_args();
static ref INDEX: Vec<u8> = { static ref INDEX: Vec<u8> = {
let mut buf = Vec::new(); let mut buf = Vec::new();
templates::index(&mut buf, COMMIT, VERSION).unwrap(); templates::index(&mut buf, COMMIT, VERSION, &OPT.domain).unwrap();
buf buf
}; };
static ref P404: Vec<u8> = { static ref P404: Vec<u8> = {
@ -87,6 +88,9 @@ struct Opt {
#[structopt(short = "h", long = "host", default_value = "0.0.0.0")] #[structopt(short = "h", long = "host", default_value = "0.0.0.0")]
/// Interface to listen on /// Interface to listen on
host: String, host: String,
#[structopt(short = "d", long = "domain", default_value = "hitsofcode.com")]
/// Interface to listen on
domain: String,
} }
fn pull(path: impl AsRef<Path>) -> Result<(), Error> { fn pull(path: impl AsRef<Path>) -> Result<(), Error> {
@ -248,11 +252,10 @@ fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=warn"); std::env::set_var("RUST_LOG", "actix_web=warn");
pretty_env_logger::init(); pretty_env_logger::init();
openssl_probe::init_ssl_cert_env_vars(); openssl_probe::init_ssl_cert_env_vars();
let opt = Opt::from_args(); let interface = format!("{}:{}", OPT.host, OPT.port);
let interface = format!("{}:{}", opt.host, opt.port);
let state = Arc::new(State { let state = Arc::new(State {
repos: opt.outdir.display().to_string(), repos: OPT.outdir.display().to_string(),
cache: opt.cachedir.display().to_string(), cache: OPT.cachedir.display().to_string(),
}); });
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()

View File

@ -1,6 +1,6 @@
@use super::base; @use super::base;
@(commit: &str, version: &str) @(commit: &str, version: &str, domain: &str)
@:base("Hits-of-Code Badges", "Hits-of-Code Badges", { @:base("Hits-of-Code Badges", "Hits-of-Code Badges", {
@ -23,7 +23,7 @@ used for GitHub, GitLab and Bitbucket repositories. Just put the following code
</p> </p>
<pre> <pre>
[![Hits-of-Code](https://hitsofcode.com/&lt;service&gt;/&lt;user&gt;/&lt;repo&gt;)](https://hitsofcode.com/view/&lt;service&gt;/&lt;user&gt;/&lt;repo&gt;) [![Hits-of-Code](https://@domain/&lt;service&gt;/&lt;user&gt;/&lt;repo&gt;)](https://@domain/view/&lt;service&gt;/&lt;user&gt;/&lt;repo&gt;)
</pre> </pre>
<p> <p>
@ -32,7 +32,7 @@ following Markdown
</p> </p>
<pre> <pre>
[![Hits-of-Code](https://hitsofcode.com/github/vbrandl/hoc)](https://hitsofcode.com/view/github/vbrandl/hoc) [![Hits-of-Code](https://@domain/github/vbrandl/hoc)](https://@domain/view/github/vbrandl/hoc)
</pre> </pre>
<p> <p>
@ -40,7 +40,7 @@ would render this badge:
</p> </p>
<pre> <pre>
<a href="https://hitsofcode.com/view/github/vbrandl/hoc"><img src="https://hitsofcode.com/github/vbrandl/hoc" <a href="https://@domain/view/github/vbrandl/hoc"><img src="https://@domain/github/vbrandl/hoc"
alt="example badge" /></a> alt="example badge" /></a>
</pre> </pre>