diff --git a/crates/ptth_server/src/file_server.rs b/crates/ptth_server/src/file_server.rs index a347a4c..86fa357 100644 --- a/crates/ptth_server/src/file_server.rs +++ b/crates/ptth_server/src/file_server.rs @@ -141,6 +141,7 @@ async fn serve_dir_json ( #[instrument (level = "debug", skip (f))] async fn serve_file ( + uri: &str, mut f: File, client_wants_body: bool, range: range::ValidParsed, @@ -211,6 +212,12 @@ async fn serve_file ( response.header (String::from ("content-range"), format! ("bytes {}-{}/{}", range.start, range.end - 1, range.end).into_bytes ()); } + // Guess MIME type based on the URI so that we can serve web games + + if uri.ends_with (".js") { + response.header ("content-type".into (), b"application/javascript".to_vec ()); + } + response.content_length = Some (content_length); if let Some (body) = body { @@ -402,7 +409,7 @@ impl FileServer { file, send_body, range, - }) => serve_file (file.into_inner (), send_body, range, headers.get ("if-none-match").map (|v| &v[..])).await?, + }) => serve_file (uri, file.into_inner (), send_body, range, headers.get ("if-none-match").map (|v| &v[..])).await?, MarkdownErr (e) => { #[cfg (feature = "markdown")] {