feat: change to rust rocket project

This commit is contained in:
jabuxas 2025-02-10 23:44:09 -03:00
parent 4ceb0fc7a6
commit 349723a770
33 changed files with 1803 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

1756
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "refinement"
version = "0.1.0"
edition = "2024"
[dependencies]
rocket = "0.5.1"
rust-embed = "8.5.0"

37
src/main.rs Normal file
View File

@ -0,0 +1,37 @@
#[macro_use]
extern crate rocket;
use std::{borrow::Cow, ffi::OsStr, path::PathBuf};
use rocket::{http::ContentType, response::content::RawHtml};
use rust_embed::Embed;
#[derive(Embed)]
#[folder = "static/"]
struct Asset;
#[get("/")]
fn index() -> Option<RawHtml<Cow<'static, [u8]>>> {
let asset = Asset::get("index.html")?;
Some(RawHtml(asset.data))
}
#[get("/dist/<file..>")]
fn dist(file: PathBuf) -> Option<(ContentType, Cow<'static, [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))
}
#[launch]
fn rocket() -> _ {
rocket::build()
// .mount("/", FileServer::from("static"))
.mount("/", routes![index, dist])
}

View File

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

Before

Width:  |  Height:  |  Size: 491 B

After

Width:  |  Height:  |  Size: 491 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

View File

@ -9,7 +9,7 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" /> <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" /> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" /> <link rel="manifest" href="/site.webmanifest" />
<link href="style.css?version=1" rel="stylesheet" /> <link href="/style.css?version=1" rel="stylesheet" />
</head> </head>
<body> <body>