add log
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -13,19 +13,16 @@ fn main() -> XResult<()> {
|
|||||||
let host = "127.0.0.1";
|
let host = "127.0.0.1";
|
||||||
let port = "8080";
|
let port = "8080";
|
||||||
let base_path = std::env::var("HOME")?;
|
let base_path = std::env::var("HOME")?;
|
||||||
|
let base_path_buff = PathBuf::from_str(&base_path)?;
|
||||||
|
|
||||||
print_message(MessageType::INFO, &format!("Base path: {}", &base_path));
|
print_message(MessageType::INFO, &format!("Base path: {}", &base_path));
|
||||||
|
print_message(MessageType::INFO, &format!("Starting server @{}:{}...", host, port));
|
||||||
|
|
||||||
println!("Starting server @{}:{}...", host, port);
|
|
||||||
let server = Server::new(move |request, mut response| {
|
let server = Server::new(move |request, mut response| {
|
||||||
// let uri = request.uri();
|
// let uri = request.uri();
|
||||||
let uri_str = request.uri().to_string();
|
let uri_str = request.uri().to_string();
|
||||||
|
|
||||||
let mut local_path_buff = match PathBuf::from_str(&base_path) {
|
let mut local_path_buff = base_path_buff.clone();
|
||||||
Ok(p) => p, Err(e) => {
|
|
||||||
return Ok(response.status(500).body(format!("{}", e).as_bytes().to_vec())?);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
local_path_buff.push(uri_str.chars().skip(1).collect::<String>());
|
local_path_buff.push(uri_str.chars().skip(1).collect::<String>());
|
||||||
let local_path = local_path_buff.as_path();
|
let local_path = local_path_buff.as_path();
|
||||||
|
|
||||||
@@ -67,6 +64,4 @@ fn main() -> XResult<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.listen(host, port);
|
server.listen(host, port);
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user