add real main page

This commit is contained in:
2024-10-04 05:05:03 +00:00
parent 6840415069
commit 6392d20ace
28 changed files with 34 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
use rocket::{futures::lock::Mutex, get, http::Status, response::Redirect, response::content::RawHtml, routes, State};
use rocket::{futures::lock::Mutex, get, fs::FileServer, http::Status, response::Redirect, response::content::RawHtml, routes, State};
use tokio_postgres::{Client, NoTls, Statement};
use std::fs::File;
@@ -29,23 +29,14 @@ async fn main() {
config.port = 3020;
let state = GlobalState { db_client: client, stmt_get_link: statements.0, stmt_add_link: statements.1 };
rocket::build()
.mount("/", routes![main_page, create, go_to_link])
.mount("/", routes![create, go_to_link])
.mount("/", FileServer::from("static"))
.manage(Mutex::new(state))
.configure(config)
.launch()
.await.unwrap();
}
#[get("/")]
fn main_page() -> Result<RawHtml<File>, Status> {
match File::open("./static/page.html") {
Ok(f) => Ok(RawHtml(f)),
Err(e) => {
eprintln!("open static page error: {}", e);
Err(Status::InternalServerError)
}
}
}
#[get("/create?<url>&<secret>&<length>&<link>")]
async fn create(state: &State<Mutex<GlobalState>>, url: &str, secret: Option<&str>, length: Option<u32>, link: Option<&str>) -> (Status, String) {
let mut allow_secret_options = false;