mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2026-05-03 03:31:56 +00:00
fixed git fuck up
This commit is contained in:
@@ -1,11 +1,35 @@
|
||||
use rocket::{get, routes};
|
||||
use rocket::{get, http::ContentType, response::content::RawHtml, routes};
|
||||
use rust_embed::Embed;
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
#[derive(Embed)]
|
||||
#[folder = "web/dist"]
|
||||
struct Asset;
|
||||
|
||||
pub async fn start_webserver() -> Result<(), rocket::Error> {
|
||||
rocket::build().mount("/", routes![index]).launch().await?;
|
||||
rocket::build()
|
||||
.mount("/", routes![static_files,index])
|
||||
.launch()
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> &'static str {
|
||||
"Hello, world!"
|
||||
fn index() -> Option<RawHtml<Cow<'static, [u8]>>> {
|
||||
let asset = Asset::get("index.html")?;
|
||||
Some(RawHtml(asset.data))
|
||||
}
|
||||
|
||||
#[get("/<file..>")]
|
||||
fn static_files(file: std::path::PathBuf) -> Option<(ContentType, Vec<u8>)> {
|
||||
let filename = file.display().to_string();
|
||||
let asset = Asset::get(&filename)?;
|
||||
let content_type = file
|
||||
.extension()
|
||||
.and_then(OsStr::to_str)
|
||||
.and_then(ContentType::from_extension)
|
||||
.unwrap_or(ContentType::Bytes);
|
||||
|
||||
Some((content_type, asset.data.into_owned()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user