I created an HTML5 app using Construct3.
how can I deploye locally with rust
HTML
C:.
│ data.json
│ **index.html**
│ style.css
│ workermain.js
└───scripts
main.js
supportcheck.js
web server unable to process javascript request in index.html.
I read the content in the xxx.js file and return it directly to the client. <-- it doesn't work
let listener = TcpListener::bind("127.0.0.1:80").unwrap();
for stream in listener.incoming() {
let stream = stream.unwrap();
handle_connection(stream);
}
fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();
let (status_line, filename, contents) = if buffer.starts_with(b"GET / HTTP/1.1\r\n") {
("HTTP/1.1 200 OK", "index.html", "")
}else if buffer.starts_with(b"GET /scripts/main.js HTTP/1.1\r\n") {
("HTTP/1.1 200 OK", "scripts/main.js", "")
}
let contents = format!(
"{}\n{}",
fs::read_to_string(filename).unwrap_or_else(|e| format!("{}", e)),
contents
);
let response = format!(
"{}\r\nContent-Length: {}\r\n\r\n{}",
status_line,
contents.len(),
contents
);
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();