feat: change to rust rocket project
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
1756
Cargo.lock
generated
Normal file
8
Cargo.toml
Normal 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
@ -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])
|
||||||
|
}
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 491 B After Width: | Height: | Size: 491 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
@ -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>
|