Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set correct MIME types in re_web_viewer_server #1602

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions crates/re_web_viewer_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,29 @@ impl Service<Request<Body>> for Svc {

#[cfg(not(feature = "__ci"))]
fn call(&mut self, req: Request<Body>) -> Self::Future {
let rsp = Response::builder();

let bytes = match req.uri().path() {
"/" | "/index.html" => &include_bytes!("../web_viewer/index.html")[..],
"/favicon.ico" => &include_bytes!("../web_viewer/favicon.ico")[..],
"/sw.js" => &include_bytes!("../web_viewer/sw.js")[..],
let response = Response::builder();

let (mime, bytes) = match req.uri().path() {
"/" | "/index.html" => ("text/html", &include_bytes!("../web_viewer/index.html")[..]),
"/favicon.ico" => (
"image/vnd.microsoft.icon",
&include_bytes!("../web_viewer/favicon.ico")[..],
),
"/sw.js" => (
"text/javascript",
&include_bytes!("../web_viewer/sw.js")[..],
),

#[cfg(debug_assertions)]
"/re_viewer.js" => &include_bytes!("../web_viewer/re_viewer_debug.js")[..],
"/re_viewer.js" => (
"text/javascript",
&include_bytes!("../web_viewer/re_viewer_debug.js")[..],
),
#[cfg(not(debug_assertions))]
"/re_viewer.js" => &include_bytes!("../web_viewer/re_viewer.js")[..],
"/re_viewer.js" => (
"text/javascript",
&include_bytes!("../web_viewer/re_viewer.js")[..],
),

"/re_viewer_bg.wasm" => {
#[cfg(feature = "analytics")]
Expand All @@ -84,24 +96,34 @@ impl Service<Request<Body>> for Svc {
#[cfg(debug_assertions)]
{
re_log::info_once!("Serving DEBUG web-viewer");
&include_bytes!("../web_viewer/re_viewer_debug_bg.wasm")[..]
(
"application/wasm",
&include_bytes!("../web_viewer/re_viewer_debug_bg.wasm")[..],
)
}
#[cfg(not(debug_assertions))]
{
&include_bytes!("../web_viewer/re_viewer_bg.wasm")[..]
(
"application/wasm",
&include_bytes!("../web_viewer/re_viewer_bg.wasm")[..],
)
}
}
_ => {
re_log::warn!("404 path: {}", req.uri().path());
let body = Body::from(Vec::new());
let rsp = rsp.status(404).body(body).unwrap();
let rsp = response.status(404).body(body).unwrap();
return future::ok(rsp);
}
};

let body = Body::from(Vec::from(bytes));
let rsp = rsp.status(200).body(body).unwrap();
future::ok(rsp)
let mut response = response.status(200).body(body).unwrap();
response.headers_mut().insert(
hyper::header::CONTENT_TYPE,
hyper::header::HeaderValue::from_static(mime),
);
future::ok(response)
}
}

Expand Down