Skip to content

Commit dfc0ace

Browse files
authored
Updates serve.rs
1 parent 86ed24c commit dfc0ace

1 file changed

Lines changed: 0 additions & 6 deletions

File tree

src/bin/serve.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::io::Read;
55
use std::path::Path;
66
use tiny_http::{Header, Request, Response, Server, StatusCode};
77

8-
/// Guess a MIME type from the file extension
98
fn mime_from_path(path: &str) -> &'static str {
109
if path.ends_with(".html") {
1110
"text/html; charset=utf-8"
@@ -28,11 +27,9 @@ fn mime_from_path(path: &str) -> &'static str {
2827
}
2928
}
3029

31-
/// Handle each incoming HTTP request
3230
fn handle_request(request: Request) {
3331
let url = request.url();
3432

35-
// Map "/" → "index.html", else strip leading "/"
3633
let path = if url == "/" {
3734
"index.html".to_string()
3835
} else {
@@ -52,19 +49,16 @@ fn handle_request(request: Request) {
5249
let mime = mime_from_path(&path);
5350
let mut resp = Response::from_data(buf);
5451

55-
// Add headers
5652
resp.add_header(
5753
Header::from_bytes("Content-Type", mime)
5854
.expect("failed to create Content-Type header"),
5955
);
6056

61-
// Add CORS headers for WASM
6257
resp.add_header(
6358
Header::from_bytes("Access-Control-Allow-Origin", "*")
6459
.expect("failed to create CORS header"),
6560
);
6661

67-
// Cache control for development
6862
resp.add_header(
6963
Header::from_bytes("Cache-Control", "no-cache, no-store, must-revalidate")
7064
.expect("failed to create Cache-Control header"),

0 commit comments

Comments
 (0)