Switch to serving static/index.html by default.
This commit is contained in:
1 parent
8dd4a287eb
commit
e6a9d393f2
1 file changed
+14
-6
+14
-6
@@ -1,5 +1,5 @@
|
|||||||
extern crate rocket;
|
use rocket::fs::FileServer;
|
||||||
|
use rocket::fs::NamedFile;
|
||||||
use rocket::http::ContentType;
|
use rocket::http::ContentType;
|
||||||
use rocket::http::Header;
|
use rocket::http::Header;
|
||||||
|
|
||||||
@@ -9,15 +9,21 @@ use crate::translate;
|
|||||||
|
|
||||||
pub async fn run_server() {
|
pub async fn run_server() {
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.mount("/", routes![hello, generate])
|
.mount("/", routes![index, healthz, generate])
|
||||||
|
.mount("/static", FileServer::from("static"))
|
||||||
.launch()
|
.launch()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/hello")]
|
#[get("/")]
|
||||||
fn hello() -> &'static str {
|
async fn index() -> Option<NamedFile> {
|
||||||
"Hello, world!"
|
NamedFile::open("static/index.html").await.ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/healthz")]
|
||||||
|
fn healthz() -> &'static str {
|
||||||
|
"ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Wrap this with memoization via https://docs.rs/michie/latest/michie/
|
// TODO: Wrap this with memoization via https://docs.rs/michie/latest/michie/
|
||||||
@@ -34,6 +40,7 @@ fn generate_binary_stl(mushroom: mushroom::Mushroom) -> Vec<u8> {
|
|||||||
return binary_stl;
|
return binary_stl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Responder class for BinarySTL or Error.
|
||||||
#[derive(Responder)]
|
#[derive(Responder)]
|
||||||
enum AsyncBinaryStlResponder {
|
enum AsyncBinaryStlResponder {
|
||||||
#[response(status = 500)]
|
#[response(status = 500)]
|
||||||
@@ -67,6 +74,7 @@ async fn generate_helper(mushroom: mushroom::Mushroom) -> AsyncBinaryStlResponde
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handler for /generate GEt endpoint.
|
||||||
#[get("/generate?<stalk_h>&<stalk_r>&<cap_h>&<cap_r>&<cap_style>")]
|
#[get("/generate?<stalk_h>&<stalk_r>&<cap_h>&<cap_r>&<cap_style>")]
|
||||||
async fn generate(
|
async fn generate(
|
||||||
stalk_h: Option<f32>,
|
stalk_h: Option<f32>,
|
||||||
|
|||||||
Reference in new issue
Block a user