Files
tauri/tauri/src/server.rs
Tensor-Programming b92eee019c [Refactor] Remove unwraps from tauri (#234)
* remove unwraps from tauri code

* refactor bundler and remove unwraps

* remove errors

* cleaup and add distinctions

* reword panic
2019-12-26 16:09:04 -05:00

32 lines
1.1 KiB
Rust

use tiny_http::{Header, Response};
pub fn asset_response(path: &str) -> Response<std::io::Cursor<Vec<u8>>> {
let asset = crate::assets::ASSETS
.get(&format!("{}{}", env!("TAURI_DIST_DIR"), path))
.expect("Could not get assets")
.into_owned();
let mut response = Response::from_data(asset);
let header;
if path.ends_with(".svg") {
header = Header::from_bytes(&b"Content-Type"[..], &b"image/svg+xml"[..])
.expect("Could not add svg+xml header");
} else if path.ends_with(".css") {
header =
Header::from_bytes(&b"Content-Type"[..], &b"text/css"[..]).expect("Could not add css header");
} else if path.ends_with(".html") {
header = Header::from_bytes(&b"Content-Type"[..], &b"text/html"[..])
.expect("Could not add html header");
} else if path.ends_with(".js") {
header = Header::from_bytes(&b"Content-Type"[..], &b"text/javascript"[..])
.expect("Could not add Javascript header");
} else {
header = Header::from_bytes(&b"Content-Type"[..], &b"application/octet-stream"[..])
.expect("Could not add octet-stream header");
}
response.add_header(header);
response
}