So I've followed the Yew sample app tutorial, served the files using Miniserve as the tutorial suggests, and it worked great.
But since I eventually want to make an app that communicates with the server using WebSockets, I want to serve it using my own server.
I tried making one, following the Single Threaded Web Server chapter of the Rust Book
use std::{fs, thread};
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
fn main() {
let server = TcpListener::bind("127.0.0.1:8080").unwrap();
for stream in server.incoming() {
let stream = stream.unwrap();
thread::spawn(|| {
handle_connection(stream);
});
}
}
fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();
let contents = fs::read_to_string("static/index.html").unwrap();
let response = format!(
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
contents.len(),
contents
);
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
}
And it worked great, but when I tried serving the index.html file from the Yew example, I received an error in the browser saying:
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec. from wasm.js: 1.
I tried looking around but couldn't find out what causes it or how to fix it.
Thanks in advance for the help!