1
0

working proof of concept

This commit is contained in:
2024-02-03 00:36:56 +00:00
parent 5bdf7a7250
commit a8076f726f
13 changed files with 2539 additions and 0 deletions

38
src/server.rs Normal file
View File

@@ -0,0 +1,38 @@
use actix_web::{web::{self, Data}, App, HttpServer};
use tera::Tera;
use crate::{handlers, templates, Args};
const ADDRESS: &str = "127.0.0.1";
pub async fn run(args: &Args) -> Result<(), ServerError> {
std::fs::create_dir_all(&args.schem_dir_path)?;
let cloned_args = args.clone();
let mut tera = Tera::default();
tera.add_raw_template("index.html", templates::INDEX_HTML)?;
HttpServer::new(move || {
App::new()
.app_data(Data::new(cloned_args.clone()))
.app_data(Data::new(tera.clone()))
.route("/robots.txt", web::get().to(handlers::robots_txt))
.route("/favicon.ico", web::get().to(handlers::favicon_ico))
.route("/", web::get().to(handlers::index))
.route("/download/{filename:.*}", web::get().to(handlers::download))
.route("/upload", web::post().to(handlers::upload))
})
.bind((ADDRESS, args.port))?
.run()
.await?;
Ok(())
}
#[derive(Debug, thiserror::Error)]
pub enum ServerError {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Tera(#[from] tera::Error),
}