use axum::{
body::Body,
http::{
Response, StatusCode,
header::{CONTENT_TYPE, HeaderValue},
},
response::IntoResponse,
};
const INDEX_HTML: &str = include_str!("../web/dist/index.html");
const APP_JS: &[u8] = include_bytes!("../web/dist/assets/index.js");
const APP_CSS: &str = include_str!("../web/dist/assets/index.css");
#[must_use]
pub fn index_response() -> Response<Body> {
response("text/html; charset=utf-8", Body::from(INDEX_HTML))
}
#[must_use]
pub fn asset_response(path: &str) -> Response<Body> {
match path {
"index.js" => response("text/javascript; charset=utf-8", Body::from(APP_JS)),
"index.css" => response("text/css; charset=utf-8", Body::from(APP_CSS)),
_ => StatusCode::NOT_FOUND.into_response(),
}
}
fn response(content_type: &'static str, body: Body) -> Response<Body> {
let mut response = Response::new(body);
response
.headers_mut()
.insert(CONTENT_TYPE, HeaderValue::from_static(content_type));
response
}