figure out how this shit actually works

This commit is contained in:
SadlyNotSappho 2023-11-21 11:58:34 -08:00
parent 3030ba3a5a
commit dfbe9e7b6c
3 changed files with 1753 additions and 2 deletions

1702
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rocket = {version="=0.5.0-rc.4",features=["secrets","json"]}

View File

@ -1,3 +1,51 @@
fn main() {
println!("Hello, world!");
#![feature(proc_macro_hygiene, decl_macro)]
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();
}