working proof of concept
This commit is contained in:
38
src/server.rs
Normal file
38
src/server.rs
Normal 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),
|
||||
}
|
||||
Reference in New Issue
Block a user