Add /index.html and /image.html
This commit is contained in:
parent
3cec866ba2
commit
a51f3fa9b5
7 changed files with 241 additions and 1 deletions
28
showbits-thermal-printer/src/server/static.rs
Normal file
28
showbits-thermal-printer/src/server/static.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use axum::{
|
||||
http::{header, StatusCode, Uri},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
use rust_embed::RustEmbed;
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "static"]
|
||||
struct StaticFiles;
|
||||
|
||||
struct StaticFile(pub String);
|
||||
|
||||
impl IntoResponse for StaticFile {
|
||||
fn into_response(self) -> Response {
|
||||
match StaticFiles::get(&self.0) {
|
||||
None => (StatusCode::NOT_FOUND, "404 Not Found").into_response(),
|
||||
Some(file) => {
|
||||
let mime = mime_guess::from_path(self.0).first_or_octet_stream();
|
||||
([(header::CONTENT_TYPE, mime.as_ref())], file.data).into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_static_file(uri: Uri) -> impl IntoResponse {
|
||||
let path = uri.path().trim_start_matches('/').to_string();
|
||||
StaticFile(path)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue