Project start

This commit is contained in:
2024-11-30 20:40:23 +01:00
commit 231c392f23
11 changed files with 418 additions and 0 deletions

23
src/renderer.rs Normal file
View File

@@ -0,0 +1,23 @@
use crate::body::Body;
use hyper::{Response, StatusCode};
use std::fs::File;
use std::io::Read;
pub(crate) fn get_static(file: &String) -> Response<Body> {
let file = read_static(file);
match file {
Ok(file) => Response::new(Body::new(file)),
Err(_) => Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::Empty)
.unwrap(),
}
}
pub(crate) fn get_rendered() {}
fn read_static(file: &String) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
let mut buf = Vec::new();
let mut file = File::open(file)?;
file.read_to_end(&mut buf)?;
Ok(buf)
}