implement a default logger

I've snuck some renames of variables too
This commit is contained in:
Damjan Georgievski 2018-07-21 14:58:27 +02:00
parent a4d895ea4a
commit a6a3d707d6
3 changed files with 13 additions and 7 deletions

View file

@ -8,6 +8,7 @@ readme = "README.md"
[dependencies] [dependencies]
actix-web = "0.7" actix-web = "0.7"
bytes = "0.4" bytes = "0.4"
env_logger = "*"
futures = "0.1" futures = "0.1"
tar = "0.4" tar = "0.4"
percent-encoding = "1.0" percent-encoding = "1.0"

View file

@ -1,5 +1,6 @@
extern crate actix_web; extern crate actix_web;
extern crate bytes; extern crate bytes;
extern crate env_logger;
extern crate futures; extern crate futures;
extern crate tar; extern crate tar;
extern crate htmlescape; extern crate htmlescape;
@ -16,13 +17,16 @@ use std::io;
// TODO cli args // TODO cli args
fn main() -> Result<(), io::Error> { fn main() -> Result<(), io::Error> {
std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let bind_addr = env::var("HTTP_ADDR").unwrap_or(String::from("0.0.0.0:8000")); let bind_addr = env::var("HTTP_ADDR").unwrap_or(String::from("0.0.0.0:8000"));
let sys = actix::System::new("static_index"); let sys = actix::System::new("http_server_rs");
server::new(web::create_app) server::new(web::create_app)
.bind(&bind_addr) .bind(&bind_addr)
.expect(&format!("Can't listen on {} ", bind_addr)) .expect(&format!("Can't listen on {} ", bind_addr))
.start(); .start();
println!("Started http server: {}", bind_addr); println!("Started http server: {}", bind_addr);
let _ = sys.run(); let _ = sys.run();

View file

@ -1,4 +1,4 @@
use actix_web::{error, fs, App, HttpRequest, HttpResponse, Responder, http::Method}; use actix_web::{error, fs, App, HttpRequest, HttpResponse, Responder, http::Method, middleware};
use futures::Stream; use futures::Stream;
use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use htmlescape::encode_minimal as escape_html_entity; use htmlescape::encode_minimal as escape_html_entity;
@ -9,10 +9,11 @@ use std::path::PathBuf;
use std; use std;
pub fn create_app() -> App { pub fn create_app() -> App {
let s = fs::StaticFiles::new(".").unwrap().show_files_listing().files_listing_renderer(handle_directory); let static_files = fs::StaticFiles::new(".").unwrap().show_files_listing().files_listing_renderer(handle_directory);
App::new() App::new()
.middleware(middleware::Logger::default())
.resource(r"/{tail:.*}.tar", |r| r.method(Method::GET).f(handle_tar)) .resource(r"/{tail:.*}.tar", |r| r.method(Method::GET).f(handle_tar))
.handler("/", s) .handler("/", static_files)
} }
fn handle_directory<'a, 'b>( fn handle_directory<'a, 'b>(