Small fixes
This commit is contained in:
@@ -39,7 +39,7 @@ fn handle_request(mut req: Request, db: db::DBPool) {
|
||||
if !(path.contains('\\') || path.contains("..") || path.contains(':')) {
|
||||
let path_str = "./static".to_owned() + &path;
|
||||
let path = std::path::Path::new(&path_str);
|
||||
if path.exists() {
|
||||
if path.is_file() {
|
||||
let resp = Response::from_file(File::open(path).unwrap());
|
||||
match path.extension().map(|s| s.to_str()).unwrap_or(None) {
|
||||
Some("html") => resp.with_header(header("content-type", "text/html; charset=utf-8")),
|
||||
@@ -175,10 +175,12 @@ fn handle_api_request(span: &mut Span, req: &mut Request, pool: db::DBPool) -> R
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Loading config...");
|
||||
let _ = config::CONFIG;
|
||||
|
||||
let db_pool: db::DBPool = db::build_pool();
|
||||
|
||||
println!("Running migrations...");
|
||||
db::run_migrations(&mut db_pool.get().unwrap());
|
||||
|
||||
if !std::path::Path::new("files").exists() {
|
||||
@@ -188,11 +190,13 @@ fn main() {
|
||||
if !std::path::Path::new("temp").is_dir() {
|
||||
std::fs::create_dir("temp").expect("Failed to create temp dir");
|
||||
}
|
||||
println!("Cleaning up temp...");
|
||||
std::fs::read_dir("temp").expect("Failed to iter temp dir").for_each(|dir| {
|
||||
std::fs::remove_file(dir.expect("Failed to retrieve temp dir entry").path())
|
||||
.expect("Failed to delete file in temp dir");
|
||||
});
|
||||
|
||||
println!("Loading metrics...");
|
||||
metrics::init(DBConnection::from(db_pool.get().unwrap()));
|
||||
|
||||
let shutdown = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
@@ -213,6 +217,7 @@ fn main() {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
println!("Listening on 0.0.0.0:2345");
|
||||
'server: loop {
|
||||
match server.recv() {
|
||||
Ok(req) => {
|
||||
@@ -226,5 +231,5 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
println!("Quitting");
|
||||
println!("Goodbye");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user