From 68404150690672d7b9bb7ca8a2f90b9ae284964c Mon Sep 17 00:00:00 2001 From: Slavasil Date: Thu, 3 Oct 2024 19:19:12 +0300 Subject: [PATCH] add placeholder main page --- src/main.rs | 20 +++++++++++++++++--- static/page.html | 10 ++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 static/page.html diff --git a/src/main.rs b/src/main.rs index 4412015..913e0a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ -use rocket::{futures::lock::Mutex, get, http::Status, response::Redirect, routes, State}; +use rocket::{futures::lock::Mutex, get, http::Status, response::Redirect, response::content::RawHtml, routes, State}; use tokio_postgres::{Client, NoTls, Statement}; +use std::fs::File; mod db; mod linkgen; @@ -24,14 +25,27 @@ async fn main() { }); db::prepare_tables(&client).await.unwrap(); let statements = db::prepare_statements(&client).await.unwrap(); + let mut config = rocket::Config::default(); + config.port = 3020; let state = GlobalState { db_client: client, stmt_get_link: statements.0, stmt_add_link: statements.1 }; rocket::build() - .mount("/", routes![create, go_to_link]) + .mount("/", routes![main_page, create, go_to_link]) .manage(Mutex::new(state)) + .configure(config) .launch() .await.unwrap(); } +#[get("/")] +fn main_page() -> Result, 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?&&&")] async fn create(state: &State>, url: &str, secret: Option<&str>, length: Option, link: Option<&str>) -> (Status, String) { let mut allow_secret_options = false; @@ -103,4 +117,4 @@ pub async fn go_to_link(state: &State>, link: &str) -> Result Err(Status::InternalServerError) } } -} \ No newline at end of file +} diff --git a/static/page.html b/static/page.html new file mode 100644 index 0000000..195b1ec --- /dev/null +++ b/static/page.html @@ -0,0 +1,10 @@ + + + + + url shortener + + +(url shortener) + +