// Windjammer HTTP Server - Showcase Portal
// Serves the Windjammer UI showcase and all examples
use std::http::*
use std::fs::*
fn main() {
println!("🎨 Windjammer Showcase Server (Pure Windjammer!)")
println!("Serving from: /Users/jeffreyfriedman/src/windjammer/crates/windjammer-ui/examples")
println!("")
println!("Starting server on http://localhost:8080")
println!("Open http://localhost:8080 to see the showcase")
println!("Press Ctrl+C to stop")
println!("")
let server = Server::new("127.0.0.1", 8080)
match server.serve(|request| handle_request(request)) {
Ok(_) => println!("Server stopped"),
Err(e) => println!("Server error: {}", e)
}
}
fn handle_request(request: ServerRequest) -> ServerResponse {
let base_dir = "/Users/jeffreyfriedman/src/windjammer/crates/windjammer-ui/examples"
let file_path = if request.path == "/" {
format!("{}/index.html", base_dir)
} else {
format!("{}{}", base_dir, request.path)
}
// Check if it's a binary file
let is_binary = file_path.ends_with(".wasm")
|| file_path.ends_with(".png")
|| file_path.ends_with(".jpg")
|| file_path.ends_with(".jpeg")
|| file_path.ends_with(".gif")
|| file_path.ends_with(".ico")
if is_binary {
// Read as binary
match read_bytes(file_path.clone()) {
Ok(data) => {
let content_type = get_content_type(file_path.clone())
ServerResponse::binary(200, data)
.header("Content-Type", content_type)
},
Err(e) => {
ServerResponse::error(404, format!("File not found: {}", request.path))
}
}
} else {
// Read as text
match read_file(file_path.clone()) {
Ok(content) => {
let content_type = get_content_type(file_path.clone())
ServerResponse::new(200, content)
.header("Content-Type", content_type)
},
Err(e) => {
ServerResponse::error(404, format!("File not found: {}", request.path))
}
}
}
}
fn get_content_type(path: string) -> string {
if path.ends_with(".html") {
"text/html"
} else if path.ends_with(".js") {
"application/javascript"
} else if path.ends_with(".wasm") {
"application/wasm"
} else if path.ends_with(".css") {
"text/css"
} else if path.ends_with(".json") {
"application/json"
} else if path.ends_with(".png") {
"image/png"
} else if path.ends_with(".jpg") || path.ends_with(".jpeg") {
"image/jpeg"
} else if path.ends_with(".gif") {
"image/gif"
} else if path.ends_with(".svg") {
"image/svg+xml"
} else if path.ends_with(".ico") {
"image/x-icon"
} else {
"application/octet-stream"
}
}