embed web source
This commit is contained in:
parent
6bd7379df3
commit
f5ef251458
3 changed files with 44 additions and 62 deletions
28
src/main.rs
28
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
use std::io::{Result};
|
||||
use std::net::{ToSocketAddrs};
|
||||
use std::{env, fs};
|
||||
use std::{env};
|
||||
|
||||
use mcstatusface::http::{HttpServer, StatusCode};
|
||||
use mcstatusface::{MinecraftStatus};
|
||||
|
@ -58,29 +58,19 @@ env!("CARGO_PKG_VERSION"));
|
|||
}
|
||||
|
||||
if request.path() == "/style/index.css" {
|
||||
match fs::read_to_string("./public/style/index.css") {
|
||||
Ok(content) => {
|
||||
let content = include_str!("public/style/index.css");
|
||||
response.set_header("Content-Type", "text/css".to_string());
|
||||
response.status(StatusCode::OK);
|
||||
response.body(content.to_string());
|
||||
return response.send();
|
||||
}
|
||||
Err(err) => {
|
||||
eprint!("failed to load index.css: {}\n", err.to_string());
|
||||
response.status(StatusCode::InternalServerError);
|
||||
response.body("Internal Server Error\n".to_string());
|
||||
return response.send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if request.path() == "/" {
|
||||
if request.headers().get("Accept").is_some_and(
|
||||
|accept| accept.contains("text/html")
|
||||
) {
|
||||
// HTML response
|
||||
match fs::read_to_string("./views/index.html") {
|
||||
Ok(mut content) => {
|
||||
let content = include_str!("views/index.html");
|
||||
response.set_header("Content-Type", "text/html".to_string());
|
||||
response.status(StatusCode::OK);
|
||||
let query_response: String;
|
||||
|
@ -129,23 +119,15 @@ env!("CARGO_PKG_VERSION"));
|
|||
}
|
||||
}
|
||||
|
||||
content = content
|
||||
let response_content = content
|
||||
.replace("{{response}}", &query_response)
|
||||
.replace("{{host}}", match request.headers().get("Host") {
|
||||
Some(host) => { host }
|
||||
None => { "mcq.bliss.town" }
|
||||
});
|
||||
response.body(content.to_string());
|
||||
response.body(response_content.to_string());
|
||||
return response.send();
|
||||
}
|
||||
Err(err) => {
|
||||
eprint!("failed to load index.html: {}\n", err.to_string());
|
||||
response.status(StatusCode::InternalServerError);
|
||||
response.body("Internal Server Error\n".to_string());
|
||||
return response.send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JSON response
|
||||
match request.query().get("s") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue