Serve favicon

This commit is contained in:
Valentin Brandl 2019-07-27 16:15:11 +02:00
parent 8e570c0594
commit 5ef0a218c2
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
3 changed files with 16 additions and 0 deletions

View File

@ -1,4 +1,6 @@
#[macro_use] #[macro_use]
extern crate actix_web;
#[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
@ -12,6 +14,7 @@ use crate::{
data::FilePath, data::FilePath,
error::Result, error::Result,
service::{Bitbucket, GitLab, Github, Service}, service::{Bitbucket, GitLab, Github, Service},
statics::FAVICON,
}; };
use actix_web::{ use actix_web::{
http::header::{self, CacheControl, CacheDirective, Expires}, http::header::{self, CacheControl, CacheDirective, Expires},
@ -79,6 +82,17 @@ fn handle_request<T: Service>(
} }
} }
#[get("/favicon.ico")]
fn favicon32() -> HttpResponse {
HttpResponse::Ok()
.content_type("image/png")
.set(CacheControl(vec![
CacheDirective::Public,
CacheDirective::MaxAge(2_592_000_000),
]))
.body(FAVICON)
}
fn main() -> Result<()> { fn main() -> Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=trace"); std::env::set_var("RUST_LOG", "actix_server=info,actix_web=trace");
pretty_env_logger::init(); pretty_env_logger::init();
@ -88,6 +102,7 @@ fn main() -> Result<()> {
App::new() App::new()
.data(Client::new()) .data(Client::new())
.wrap(middleware::Logger::default()) .wrap(middleware::Logger::default())
.service(favicon32)
.route( .route(
"/github/{user}/{repo}/{commit}/{file:.*}", "/github/{user}/{repo}/{commit}/{file:.*}",
web::get().to_async(handle_request::<Github>), web::get().to_async(handle_request::<Github>),

View File

@ -1,4 +1,5 @@
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png");
lazy_static! { lazy_static! {
pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION); pub(crate) static ref USER_AGENT: String = format!("gitache/{}", VERSION);
} }

BIN
static/favicon32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 983 B