figure out how this shit actually works
This commit is contained in:
parent
3030ba3a5a
commit
dfbe9e7b6c
File diff suppressed because it is too large
Load Diff
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
rocket = {version="=0.5.0-rc.4",features=["secrets","json"]}
|
||||||
|
|
52
src/main.rs
52
src/main.rs
|
@ -1,3 +1,51 @@
|
||||||
fn main() {
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
println!("Hello, world!");
|
|
||||||
|
use std::fs;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate rocket;
|
||||||
|
use rocket::{tokio::time::{sleep, Duration}, fs::FileServer};
|
||||||
|
use rocket::serde::{Deserialize, json::Json};
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
fn hello() -> String {
|
||||||
|
fs::read_to_string("/home/sadlynotsappho/Projects/Web/website/root/index.html").unwrap()
|
||||||
|
// format!("hi!!!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/book/<card>/<isbn>")]
|
||||||
|
fn get_book(card: String, isbn: String) -> String {
|
||||||
|
format!("You're checking out the book {isbn}, with the account {card}.")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/delay/<time>")]
|
||||||
|
async fn delay(time: u64) -> String {
|
||||||
|
sleep(Duration::from_secs(time)).await;
|
||||||
|
format!("waited for {time} seconds")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[serde(crate = "rocket::serde")]
|
||||||
|
struct LoginInfo {
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/login", data = "<info>")]
|
||||||
|
async fn login(info: Json<LoginInfo>) -> &'static str {
|
||||||
|
if info.username == "sadlynotsappho" && info.password == "thebestpasswordofalltime" {
|
||||||
|
"logged in!"
|
||||||
|
} else {
|
||||||
|
"invalid login info :("
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rocket::main]
|
||||||
|
async fn main() {
|
||||||
|
let _rocket = rocket::build()
|
||||||
|
.mount("/", routes![hello, get_book, delay, login])
|
||||||
|
.mount("/root", FileServer::from("/home/sadlynotsappho/Projects/Web/website/root"))
|
||||||
|
.launch()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue